libauth

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProviderSet = wire.NewSet(NewAuth)

Functions

func NewClaims

func NewClaims() jwtv4.Claims

func RawFromContext added in v0.2.1

func RawFromContext(ctx context.Context) string

Types

type Auth

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

func NewAuth

func NewAuth(config *conf.Auth) (*Auth, error)

func (*Auth) GeneratePassword

func (a *Auth) GeneratePassword(password string) (string, error)

func (*Auth) GenerateToken

func (a *Auth) GenerateToken(
	uid model.InternalID,
	pid model.InternalID,
	claimsType ClaimsType,
	userType UserType,
	transferMetadata any,
	expire time.Duration,
) (string, error)

func (*Auth) KeyFunc

func (a *Auth) KeyFunc(t ClaimsType) jwtv4.Keyfunc

type Claims

type Claims struct {
	UserID           model.InternalID `json:"uid,string"`
	PorterID         model.InternalID `json:"pid,string,omitempty"`
	Type             ClaimsType       `json:"ct"`
	UserType         UserType         `json:"ut"`
	TransferMetadata any              `json:"tm,omitempty"`
	jwtv4.RegisteredClaims
}

func FromContext

func FromContext(ctx context.Context) *Claims

func FromContextAssertUserType added in v0.0.6

func FromContextAssertUserType(ctx context.Context, userTypes ...UserType) *Claims

type ClaimsType

type ClaimsType int
const (
	ClaimsTypeUnspecified ClaimsType = iota
	ClaimsTypeAccessToken
	ClaimsTypeRefreshToken
	ClaimsTypeUploadToken
	ClaimsTypeDownloadToken
)

type UserType

type UserType int
const (
	UserTypeUnspecified UserType = iota
	UserTypeAdmin
	UserTypeNormal
	UserTypeSentinel
	UserTypePorter
)

Jump to

Keyboard shortcuts

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