tokenutil

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataKey = "waypoint-token"
View Source
const (
	// TokenMagic is used as a byte sequence prepended to the encoded TokenTransport to identify
	// the token as valid before attempting to decode it. This is mostly a nicity to improve
	// understanding of the token data and error messages.
	TokenMagic = "wp24"
)

Variables

View Source
var (
	ErrInvalidToken = errors.New("invalid token detected")
)

Functions

func SetupExternalCreds

func SetupExternalCreds(ctx context.Context, log hclog.Logger, token string) (credentials.PerRPCCredentials, error)

func StripCreds

func StripCreds(tt *pb.TokenTransport) (string, error)

StripCreds removes the credentials from the given TokenTransport and repackages it up as a string. This doesn't invalidate the signature, because the signature is only against the body field of the transport.

func TokenDecode

func TokenDecode(token string) (*pb.TokenTransport, *pb.Token, error)

TokenDecode provides the ability to decode a waypoint token into the embedded protobuf. WARNING: This function is unable to verify the token, only the server that generate the server can do that.

func TokenFromContext

func TokenFromContext(ctx context.Context) string

TokenFromContext extracts a token (if any) from the given context.

func TokenWithContext

func TokenWithContext(ctx context.Context, t string) context.Context

TokenWithContext stores a token on the given context. If this context is used by a connection created by serverclient, this token will take priority for requests.

Types

type ContextToken

type ContextToken string

ContextToken implements grpc.WithPerRPCCredentials and extracts the token from the context or otherwise falls back to a default string value (which might be empty).

func (ContextToken) GetRequestMetadata

func (t ContextToken) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

func (ContextToken) RequireTransportSecurity

func (t ContextToken) RequireTransportSecurity() bool

type StaticToken

type StaticToken string

This is a weird type that only exists to satisify the interface required by grpc.WithPerRPCCredentials. That api is designed to incorporate things like OAuth but in our case, we really just want to send this static token through, but we still need to the dance.

func (StaticToken) GetRequestMetadata

func (t StaticToken) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

func (StaticToken) RequireTransportSecurity

func (t StaticToken) RequireTransportSecurity() bool

type TokenAndAuth

type TokenAndAuth struct {
	credentials.PerRPCCredentials
	Token string
}

TokenAndAuth is a special version of PerRPCCredentials that lets us pass the authorization metadata as well as the waypoint token in a separate field

func (*TokenAndAuth) GetRequestMetadata

func (t *TokenAndAuth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error)

Jump to

Keyboard shortcuts

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