Help us shape the future of Go! Take the 2026 Go Developer Survey

httpauthclient

package
v1.3.104 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package httpauthclient pkg/httpauthclient/client.go c0-com-http

Package httpauthclient pkg/httpauthclient/nonce.go c0-com-http

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractError

func ExtractError(r io.Reader) error

ExtractError returns the decoded error message from Body.

func PayloadWithNonce

func PayloadWithNonce(payload []byte, nonce Nonce) []byte

PayloadWithNonce returns the concatenation of payload and nonce.

func Sign

func Sign(payload []byte, nonce Nonce, sec cipher.SecKey) (cipher.Sig, error)

Sign signs the Hash of payload and nonce

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements Client for auth services.

func NewClient

func NewClient(ctx context.Context, addr string, key cipher.PubKey, sec cipher.SecKey, client *http.Client, clientPublicIP string,
	mLog *logging.MasterLogger) (*Client, error)

NewClient creates a new client setting a public key to the client to be used for Auth. When keys are set, the client will sign request before submitting. The signature information is transmitted in the header using: * SW-Public: The specified public key * SW-Nonce: The nonce for that public key * SW-Sig: The signature of the payload + the nonce

func (*Client) Addr

func (c *Client) Addr() string

Addr returns sanitized address of the client

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do performs a new authenticated Request and returns the response. Internally, if the request was successful nonce is incremented

func (*Client) IncrementNonce

func (c *Client) IncrementNonce()

IncrementNonce increments client's current nonce.

func (*Client) Nonce

func (c *Client) Nonce(ctx context.Context, key cipher.PubKey) (Nonce, error)

Nonce calls the remote API to retrieve the next expected nonce

func (*Client) SetNonce

func (c *Client) SetNonce(n Nonce)

SetNonce sets client current nonce to given nonce

func (*Client) SetPublicIPFunc

func (c *Client) SetPublicIPFunc(fn func() string)

SetPublicIPFunc makes the SW-PublicIP header follow fn, so a visor that moves to another network stops declaring the address it had at startup.

type Error

type Error struct {
	Error string `json:"error"`
}

Error is the object returned to the client when there's an error.

type HTTPError

type HTTPError struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

HTTPError is included in an HTTPResponse

type HTTPResponse

type HTTPResponse struct {
	Error *HTTPError  `json:"error,omitempty"`
	Data  interface{} `json:"data,omitempty"`
}

HTTPResponse represents the http response struct

type NextNonceResponse

type NextNonceResponse struct {
	Edge      cipher.PubKey `json:"edge"`
	NextNonce Nonce         `json:"next_nonce"`
}

NextNonceResponse represents a ServeHTTP response for json encoding

type Nonce

type Nonce uint64

Nonce is used to sign requests in order to avoid replay attack

func (Nonce) String

func (n Nonce) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL