rpcauth

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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