Documentation ¶
Index ¶
- func GetUserPrincipalFromContext(ctx context.Context) string
- func JwtUserDetailsSign(params JwtUserDetailsSignParams, minimizeToken bool) (string, error)
- func WithUserDetails(ctx context.Context, userDetails UserDetails) context.Context
- type JwtUserClaims
- type JwtUserDetailsSignParams
- type UserDetails
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JwtUserDetailsSign ¶
func JwtUserDetailsSign(params JwtUserDetailsSignParams, minimizeToken bool) (string, error)
func WithUserDetails ¶
func WithUserDetails(ctx context.Context, userDetails UserDetails) context.Context
Types ¶
type JwtUserClaims ¶
type JwtUserClaims struct { // the `iss` (Issuer) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1 Issuer string `json:"iss,omitempty"` // the `sub` (Subject) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2 Subject string `json:"sub,omitempty"` // the `aud` (Audience) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3 Audience jwt.ClaimStrings `json:"aud,omitempty"` // the `exp` (Expiration Time) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4 ExpiresAt *jwt.NumericDate `json:"exp,omitempty"` // the `nbf` (Not Before) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5 NotBefore *jwt.NumericDate `json:"nbf,omitempty"` // the `iat` (Issued At) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.6 IssuedAt *jwt.NumericDate `json:"iat,omitempty"` // the `jti` (JWT ID) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7 ID string `json:"jti,omitempty"` // username Username string `json:"username,omitempty"` Roles []string `json:"roles,omitempty"` UserId string `json:"uid,omitempty"` Scopes []string `json:"scopes,omitempty"` Permissions []*resource_model.Permission `json:"permissions,omitempty"` }
func (*JwtUserClaims) Valid ¶
func (c *JwtUserClaims) Valid() error
func (*JwtUserClaims) VerifyExpiresAt ¶
func (c *JwtUserClaims) VerifyExpiresAt(cmp time.Time, req bool) bool
VerifyExpiresAt compares the exp claim against cmp (cmp < exp). If req is false, it will return true, if exp is unset.
func (*JwtUserClaims) VerifyIssuedAt ¶
func (c *JwtUserClaims) VerifyIssuedAt(cmp time.Time, req bool) bool
VerifyIssuedAt compares the iat claim against cmp (cmp >= iat). If req is false, it will return true, if iat is unset.
func (*JwtUserClaims) VerifyNotBefore ¶
func (c *JwtUserClaims) VerifyNotBefore(cmp time.Time, req bool) bool
VerifyNotBefore compares the nbf claim against cmp (cmp >= nbf). If req is false, it will return true, if nbf is unset.
type JwtUserDetailsSignParams ¶
type JwtUserDetailsSignParams struct { Key rsa.PrivateKey UserDetails UserDetails ExpiresAt time.Time Issuer string }
type UserDetails ¶
type UserDetails struct { UserId string `json:"userId"` Username string `json:"username"` Permissions []*resource_model.Permission `json:"permissions"` Roles []string `json:"roles"` }
func GetUserDetailsFromContext ¶
func GetUserDetailsFromContext(ctx context.Context) *UserDetails
func JwtVerifyAndUnpackUserDetails ¶
func JwtVerifyAndUnpackUserDetails(key rsa.PublicKey, tokenContent string) (*UserDetails, error)
Click to show internal directories.
Click to hide internal directories.