auth

package
v0.0.0-...-8683e0c Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleKey     = "role"
	UserNameKey = "user_name"
)

Variables

This section is empty.

Functions

func GetRole

func GetRole(ctx context.Context) (string, bool)

func GetUserID

func GetUserID(ctx context.Context) (entity.UserID, bool)

func IsAdmin

func IsAdmin(ctx context.Context) bool

func SetRole

func SetRole(ctx context.Context, tok jwt.Token) context.Context

func SetUserID

func SetUserID(ctx context.Context, uid entity.UserID) context.Context

Types

type JWTer

type JWTer struct {
	PrivateKey, PublicKey jwk.Key
	Store                 Store
	Clocker               clock.Clocker
}

func NewJWTer

func NewJWTer(s Store, c clock.Clocker) (*JWTer, error)

func (*JWTer) FillContext

func (j *JWTer) FillContext(r *http.Request) (*http.Request, error)

func (*JWTer) GenerateToken

func (j *JWTer) GenerateToken(ctx context.Context, u entity.User) ([]byte, error)

func (*JWTer) GetToken

func (j *JWTer) GetToken(ctx context.Context, r *http.Request) (jwt.Token, error)

type Store

type Store interface {
	Save(ctx context.Context, key string, userID entity.UserID) error
	Load(ctx context.Context, key string) (entity.UserID, error)
}

Jump to

Keyboard shortcuts

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