rpcauth

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTokenFromHTTPHeaders

func GetTokenFromHTTPHeaders(headers http.Header) (string, error)

GetTokenFromHTTPHeaders gets the current authentication token from the HTTP headers, if there is one.

func GetTokenFromHeader

func GetTokenFromHeader(ctx context.Context) (string, error)

GetTokenFromHeader gets the current authentication token, if there is one.

func WithContextUser added in v1.1.1

func WithContextUser(ctx context.Context, user *User) context.Context

WithContextUser sets the user on the context. It is intended to be used by interceptors following token authentication.

func WithToken

func WithToken(ctx context.Context, token string) context.Context

WithToken adds the token to the context via a header.

func WithTokenIfNoneSet added in v1.0.0

func WithTokenIfNoneSet(ctx context.Context, token string) context.Context

WithTokenIfNoneSet adds the token to the context via a header if none is already set. If a token is already set on the header, this function just returns the context as is.

Types

type Authenticator

type Authenticator interface {
	Authenticate(ctx context.Context, token string) (*User, error)
}

Authenticator defines the interface used to authenticate a token.

type AuthenticatorFunc

type AuthenticatorFunc func(context.Context, string) (*User, error)

AuthenticatorFunc is a function that implements Authenticator

func (AuthenticatorFunc) Authenticate

func (f AuthenticatorFunc) Authenticate(ctx context.Context, token string) (*User, error)

Authenticate implements Authenticator.

type User

type User struct {
	Subject string
}

User describes an authenticated user.

func GetUser

func GetUser(ctx context.Context) (*User, bool)

GetUser gets the currently authenticated user, if there is one. It returns nil, false, if there is no authenticated user.

Jump to

Keyboard shortcuts

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