gatewaytokens

package
v3.32.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gatewaytokens provides functions to work with GatewayTokens.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AuthType is the type of authentication.
	AuthType = "GatewayToken"
)

Functions

func AuthenticatedContext

func AuthenticatedContext(ctx context.Context) (context.Context, error)

AuthenticatedContext checks the context for a gatewaytokens.Token. If it exists, it generates a new GatewayToken with timestamp set and the hash calculated. The function returns a context with the GatewayToken as a metadata item. If there is no gatewaytokens.Token in the context, the function returns the original context.

func DecodeFromString

func DecodeFromString(s string) (*ttnpb.GatewayToken, error)

DecodeFromString decodes the GatewayToken from a hex encoded string.

func EncodeToString added in v3.32.0

func EncodeToString(token *ttnpb.GatewayToken) (string, error)

EncodeToString encodes the GatewayToken to a hex encoded string.

func NewContext

func NewContext(ctx context.Context, token *Token) context.Context

NewContext returns a new context with the given gatewaytokens.Token.

func Verify

func Verify(
	ctx context.Context, token *ttnpb.GatewayToken, validity time.Duration, ks KeyService,
) (*ttnpb.Rights, error)

Verify verifies the hash of the payload of a GatewayToken. If verified, the rights embedded in the token are retrieved. The function also checks if the token is still valid.

Types

type KeyService

type KeyService interface {
	HMACHash(ctx context.Context, payload []byte, id string) ([]byte, error)
}

KeyService provides HMAC hashing.

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token wraps ttnpb.GatewayToken with additional semantics.

func FromContext

func FromContext(ctx context.Context) (*Token, bool)

FromContext returns the gatewaytokens.Token from the context.

func New

func New(
	keyID string,
	ids *ttnpb.GatewayIdentifiers,
	rights *ttnpb.Rights,
	ks KeyService,
) *Token

New generates a new Token with the given information.

func (*Token) Generate

func (t *Token) Generate(ctx context.Context) (ret *ttnpb.GatewayToken, err error)

Generate generates a new ttnpb.GatewayToken with the checksum calculated and the timestamp set. This functions allows generating multiple tokens with the same information but different timestamps.

Jump to

Keyboard shortcuts

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