rpcauth

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTokenFromHTTPHeaders added in v0.37.1

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

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

func GetTokenFromHeader added in v0.37.1

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

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

func NewServerInterceptor

func NewServerInterceptor(authenticator Authenticator) rpc.ServerInterceptor

NewServerInterceptor returns a new ServerInterceptor.

func WithToken

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

WithToken adds the token to the context via a header.

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