Documentation ¶
Overview ¶
Package gatewaytokens provides functions to work with GatewayTokens.
Index ¶
- Variables
- func AuthenticatedContext(ctx context.Context) (context.Context, error)
- func DecodeFromString(s string) (*ttnpb.GatewayToken, error)
- func EncodeToString(token *ttnpb.GatewayToken) (string, error)
- func NewContext(ctx context.Context, token *Token) context.Context
- func Verify(ctx context.Context, token *ttnpb.GatewayToken, validity time.Duration, ...) (*ttnpb.Rights, error)
- type KeyService
- type Token
Constants ¶
This section is empty.
Variables ¶
var (
// AuthType is the type of authentication.
AuthType = "GatewayToken"
)
Functions ¶
func AuthenticatedContext ¶
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 ¶
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 ¶
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.