token

package
v0.0.0-...-82f6397 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAccessToken

func CreateAccessToken(user *models.User, roles, scopes []string, hostName, nonce, loginMethod string) (string, int64, error)

CreateAccessToken util to create JWT token, based on user information, roles config and CUSTOM_ACCESS_TOKEN_SCRIPT

func CreateAdminAuthToken

func CreateAdminAuthToken(tokenType string, c *gin.Context) (string, error)

CreateAdminAuthToken creates the admin token based on secret key

func CreateIDToken

func CreateIDToken(user *models.User, roles []string, hostname, nonce, atHash, cHash, loginMethod string) (string, int64, error)

CreateIDToken util to create JWT token, based on user information, roles config and CUSTOM_ACCESS_TOKEN_SCRIPT For response_type (code) / authorization_code grant nonce should be empty for implicit flow it should be present to verify with actual state

func CreateRefreshToken

func CreateRefreshToken(user *models.User, roles, scopes []string, hostname, nonce, loginMethod string) (string, int64, error)

CreateRefreshToken util to create JWT token

func CreateVerificationToken

func CreateVerificationToken(email, tokenType, hostname, nonceHash, redirectURL string) (string, error)

CreateVerificationToken creates a verification JWT token

func GetAccessToken

func GetAccessToken(gc *gin.Context) (string, error)

GetAccessToken returns the access token from the request (either from header or cookie)

func GetAdminAuthToken

func GetAdminAuthToken(gc *gin.Context) (string, error)

GetAdminAuthToken helps in getting the admin token from the request cookie

func GetIDToken

func GetIDToken(gc *gin.Context) (string, error)

GetIDToken returns the id token from the request header

func IsSuperAdmin

func IsSuperAdmin(gc *gin.Context) bool

IsSuperAdmin checks if user is super admin

func ParseJWTToken

func ParseJWTToken(token string) (jwt.MapClaims, error)

ParseJWTToken common util to parse jwt token

func SignJWTToken

func SignJWTToken(claims jwt.MapClaims) (string, error)

SignJWTToken common util to sing jwt token

func ValidateAccessToken

func ValidateAccessToken(gc *gin.Context, accessToken string) (map[string]interface{}, error)

Function to validate access token for authorizer apis (profile, update_profile)

func ValidateJWTClaims

func ValidateJWTClaims(claims jwt.MapClaims, hostname, nonce, subject string) (bool, error)

ValidateJWTClaims common util to validate claims

func ValidateJWTTokenWithoutNonce

func ValidateJWTTokenWithoutNonce(claims jwt.MapClaims, hostname, subject string) (bool, error)

ValidateJWTTokenWithoutNonce common util to validate claims without nonce

func ValidateRefreshToken

func ValidateRefreshToken(gc *gin.Context, refreshToken string) (map[string]interface{}, error)

Function to validate refreshToken

Types

type JWTToken

type JWTToken struct {
	Token     string `json:"token"`
	ExpiresAt int64  `json:"expires_at"`
}

JWTToken is a struct to hold JWT token and its expiration time

type SessionData

type SessionData struct {
	Subject     string   `json:"sub"`
	Roles       []string `json:"roles"`
	Scope       []string `json:"scope"`
	Nonce       string   `json:"nonce"`
	IssuedAt    int64    `json:"iat"`
	ExpiresAt   int64    `json:"exp"`
	LoginMethod string   `json:"login_method"`
}

SessionData

func CreateSessionToken

func CreateSessionToken(user *models.User, nonce string, roles, scope []string, loginMethod string) (*SessionData, string, int64, error)

CreateSessionToken creates a new session token

func ValidateBrowserSession

func ValidateBrowserSession(gc *gin.Context, encryptedSession string) (*SessionData, error)

type SessionOrAccessTokenData

type SessionOrAccessTokenData struct {
	UserID      string
	LoginMethod string
	Nonce       string
}

SessionOrAccessTokenData is a struct to hold session or access token data

func GetUserIDFromSessionOrAccessToken

func GetUserIDFromSessionOrAccessToken(gc *gin.Context) (*SessionOrAccessTokenData, error)

GetUserIDFromSessionOrAccessToken returns the user id from the session or access token

type Token

type Token struct {
	FingerPrint string `json:"fingerprint"`
	// Session Token
	FingerPrintHash       string    `json:"fingerprint_hash"`
	SessionTokenExpiresAt int64     `json:"expires_at"`
	RefreshToken          *JWTToken `json:"refresh_token"`
	AccessToken           *JWTToken `json:"access_token"`
	IDToken               *JWTToken `json:"id_token"`
}

Token object to hold the finger print and refresh token information

func CreateAuthToken

func CreateAuthToken(gc *gin.Context, user *models.User, roles, scope []string, loginMethod, nonce string, code string) (*Token, error)

CreateAuthToken creates a new auth token when userlogs in

Jump to

Keyboard shortcuts

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