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

httppeeridauth

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 15 Imported by: 5

Documentation

Index

Constants

View Source
const PeerIDAuthScheme = handshake.PeerIDAuthScheme
View Source
const ProtocolID = "/http-peer-id-auth/1.0.0"

Variables

This section is empty.

Functions

func HasAuthHeader added in v0.41.0

func HasAuthHeader(r *http.Request) bool

HasAuthHeader checks if the HTTP request contains an Authorization header that starts with the PeerIDAuthScheme prefix.

Types

type ClientPeerIDAuth

type ClientPeerIDAuth struct {
	PrivKey  crypto.PrivKey
	TokenTTL time.Duration
	// contains filtered or unexported fields
}

func (*ClientPeerIDAuth) AuthenticateWithRoundTripper added in v0.41.0

func (a *ClientPeerIDAuth) AuthenticateWithRoundTripper(rt http.RoundTripper, req *http.Request) (peer.ID, *http.Response, error)

func (*ClientPeerIDAuth) AuthenticatedDo

func (a *ClientPeerIDAuth) AuthenticatedDo(client *http.Client, req *http.Request) (peer.ID, *http.Response, error)

AuthenticatedDo is like http.Client.Do, but it does the libp2p peer ID auth handshake if needed.

It is recommended to pass in an http.Request with `GetBody` set, so that this method can retry sending the request in case a previously used token has expired.

func (*ClientPeerIDAuth) HasToken added in v0.41.0

func (a *ClientPeerIDAuth) HasToken(hostname string) bool

type ServerPeerIDAuth

type ServerPeerIDAuth struct {
	PrivKey  crypto.PrivKey
	TokenTTL time.Duration
	Next     func(peer peer.ID, w http.ResponseWriter, r *http.Request)
	// NoTLS is a flag that allows the server to accept requests without a TLS
	// ServerName. Used when something else is terminating the TLS connection.
	NoTLS bool
	// Required when NoTLS is true. The server will only accept requests for
	// which the Host header returns true.
	ValidHostnameFn func(hostname string) bool

	HmacKey []byte
	// contains filtered or unexported fields
}

func (*ServerPeerIDAuth) ServeHTTP

func (a *ServerPeerIDAuth) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface for PeerIDAuth. It will attempt to authenticate the request using using the libp2p peer ID auth scheme. If a Next handler is set, it will be called on authenticated requests.

func (*ServerPeerIDAuth) ServeHTTPWithNextHandler added in v0.41.0

func (a *ServerPeerIDAuth) ServeHTTPWithNextHandler(w http.ResponseWriter, r *http.Request, next func(peer.ID, http.ResponseWriter, *http.Request))

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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