auth

package
v0.0.0-...-9ed9871 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RoleAdmin = Role{"ADMIN"}
	RoleUser  = Role{"USER"}
)

Functions

func SetClaims

func SetClaims(ctx context.Context, claims Claims) context.Context

Types

type Auth

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

Auth is to used for authenticate clients

func New

func New(activeKID string, keyLookup KeyLookup) (*Auth, error)

func (*Auth) GenerateToken

func (a *Auth) GenerateToken(claims Claims) (string, error)

func (*Auth) ValidateToken

func (a *Auth) ValidateToken(tokenString string) (Claims, error)

type Claims

type Claims struct {
	jwt.RegisteredClaims `json:"registered"`
	Roles                []Role `json:"roles"`
}

func GetClaims

func GetClaims(ctx context.Context) (Claims, error)

func (Claims) Authorized

func (c Claims) Authorized(roles ...Role) bool

type KeyLookup

type KeyLookup interface {
	PrivateKey(kid string) (*rsa.PrivateKey, error)
	PublicKey(kid string) (*rsa.PublicKey, error)
}

private and public keys for JWT use

type Role

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

func MustParseRole

func MustParseRole(value string) Role

func ParseRole

func ParseRole(value string) (Role, error)

func (Role) Equal

func (r Role) Equal(other Role) bool

func (*Role) MarshalText

func (r *Role) MarshalText() ([]byte, error)

func (Role) Name

func (r Role) Name() string

func (*Role) UnmarshalText

func (r *Role) UnmarshalText(data []byte) error

Jump to

Keyboard shortcuts

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