authtoken

package
v0.0.0-...-d09923a Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: LGPL-2.1 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JwtAlgoHs256             = "HS256"
	JwtAlgoRs256             = "RS256"
	JwtEdDsa                 = "EdDSA"
	JwtTimeToleranceMins     = 3
	JwtAccessTokenExpiryMax  = 60 * 24     // 1 day
	JwtRefreshTokenExpiryMax = 60 * 24 * 7 // 7 days
	JwtRefreshTokenExpiryMin = 15          // 15 minutes
)
View Source
const (
	JwtPurposeAccessToken  = JwtPurpose("access_token")
	JwtPurposeRefreshToken = JwtPurpose("refresh_token")
)
View Source
const JwtClaimUserType = "usrtype"

JwtClaimUserType carries the IAM user type (`user` | `service`) of the token's subject in the access and refresh tokens. Its values are the principal kinds they map to.

Variables

This section is empty.

Functions

func InitSubModule

func InitSubModule() error

func PrincipalKindFromClaims

func PrincipalKindFromClaims(claims jwt.Claims) corectx.PrincipalKind

PrincipalKindFromClaims maps the user type claim to the principal kind of the request. A token without the claim predates it and was issued to a person, so it answers user, which keeps every token issued before the claim existed working exactly as it did.

func UserTypeClaims

func UserTypeClaims(userType string) map[string]any

UserTypeClaims is the custom-claim set CreateJwt needs to carry userType.

Types

type AuthTokenService

type AuthTokenService interface {
	CreateJwt(ctx corectx.Context, param CreateJwtParam) (*CreateJwtResult, error)
	VerifyJwt(ctx corectx.Context, param VerifyJwtParam) (*VerifyJwtResult, error)
}

func NewAuthTokenServiceImpl

func NewAuthTokenServiceImpl(param NewAuthTokenServiceImplParam) AuthTokenService

type AuthTokenServiceImpl

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

func (*AuthTokenServiceImpl) CreateJwt

func (this *AuthTokenServiceImpl) CreateJwt(ctx corectx.Context, param CreateJwtParam) (*CreateJwtResult, error)

func (*AuthTokenServiceImpl) VerifyJwt

func (this *AuthTokenServiceImpl) VerifyJwt(ctx corectx.Context, param VerifyJwtParam) (*VerifyJwtResult, error)

type CreateJwtParam

type CreateJwtParam struct {
	// Custom claims other than the registered claims.
	// Any claims collision with the registered claims will be overridden.
	CustomClaims map[string]any

	Purpose JwtPurpose

	// Value of the "jti" claim.
	Jti *string

	// Value of the "sub" claim.
	Sub string
}

type CreateJwtResult

type CreateJwtResult struct {
	Claims jwt.MapClaims
	Token  string
}

type JwtPurpose

type JwtPurpose string

type NewAuthTokenServiceImplParam

type NewAuthTokenServiceImplParam struct {
	dig.In
	Logger    logging.LoggerService
	ConfigSvc config.ConfigService
}

type VerifyJwtParam

type VerifyJwtParam struct {
	Token string
}

type VerifyJwtResult

type VerifyJwtResult struct {
	IsOk   bool
	Claims jwt.MapClaims
	// Value of the "jti" from `Claims`.
	Jti string
}

Jump to

Keyboard shortcuts

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