httppeeridauth

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 14 Imported by: 2

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

This section is empty.

Types

type ClientPeerIDAuth

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

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.

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

	Hmac hash.Hash
	// 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.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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