authorization

package
v0.0.0-...-ebd6d4f Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSigningMethod = errors.New("invalid signing method")
	ErrInvalidToken         = errors.New("invalid token")
)

Functions

func NewToken

func NewToken(kind AuthKind, id uint, expiry time.Time, key crypto.PrivateKey) (string, error)

Create a new token of a specified kind, for specified ID.

func NewTokenFromAuthorization

func NewTokenFromAuthorization(auth Authorization, expiry time.Time, key crypto.PrivateKey) (string, error)

Create a new token from an Authorization.

func ParseToken

func ParseToken(tokenString string, pubkey crypto.PublicKey) (AuthKind, uint, *Claims, error)

Parse a signed token. Check if it is valid and return the kind of token and the corresponding ID.

Types

type AuthKind

type AuthKind string

Kind of authorization.

const (
	AdminToken             AuthKind = "adminToken"
	AccountToken           AuthKind = "accountToken"
	DeviceToken            AuthKind = "deviceToken"
	AccountActivationToken AuthKind = "accountActivationToken"
	InvalidToken           AuthKind = "invalidToken"
)

type Authorization

type Authorization struct {
	Kind   AuthKind
	ID     uint
	Claims *Claims
}

An Authorization is used to check for permissions.

func ParseTokenToAuthorization

func ParseTokenToAuthorization(tokenString string, pubkey crypto.PublicKey) (*Authorization, error)

func (*Authorization) IsKind

func (a *Authorization) IsKind(kind AuthKind) bool

Returns if the Authorization is of the specified kind.

type Claims

type Claims struct {
	jwt.RegisteredClaims
	Kind AuthKind `json:"kind"`
}

Claims contained in the JWT.

Jump to

Keyboard shortcuts

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