session

package
v0.0.0-...-b59dafb Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RefreshAPIPath = "/session/refresh"
	SignoutAPIPath = "/signout"

	AntiCSRF_VIA_TOKEN         = "VIA_TOKEN"
	AntiCSRF_VIA_CUSTOM_HEADER = "VIA_CUSTOM_HEADER"
	AntiCSRF_NONE              = "NONE"

	CookieSameSite_NONE   = "none"
	CookieSameSite_LAX    = "lax"
	CookieSameSite_STRICT = "strict"
)
View Source
const RECIPE_ID = "session"

Variables

View Source
var HEADERS = []string{
	"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsInZlcnNpb24iOiIxIn0=",
	"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsInZlcnNpb24iOiIyIn0=",
}
View Source
var JWKCacheMaxAgeInMs int64 = 60000
View Source
var JWKRefreshRateLimit = 500

Functions

func AfterEach

func AfterEach()

func BeforeEach

func BeforeEach()

func BuildFrontToken

func BuildFrontToken(userId string, atExpiry uint64, jwtPayload interface{}) string

func ClearSessionFromAllTokenTransferMethods

func ClearSessionFromAllTokenTransferMethods(config sessmodels.TypeNormalisedInput, req *http.Request, res http.ResponseWriter) error

func CreateJWT

func CreateJWT(payload map[string]interface{}, validitySecondsPointer *uint64, useStaticSigningKey *bool, userContext ...supertokens.UserContext) (jwtmodels.CreateJWTResponse, error)

func CreateNewSession

func CreateNewSession(req *http.Request, res http.ResponseWriter, tenantId string, userID string, accessTokenPayload map[string]interface{}, sessionDataInDatabase map[string]interface{}, userContext ...supertokens.UserContext) (sessmodels.SessionContainer, error)

func CreateNewSessionInRequest

func CreateNewSessionInRequest(req *http.Request, res http.ResponseWriter, tenantId string, config sessmodels.TypeNormalisedInput, appInfo supertokens.NormalisedAppinfo, recipeInstance Recipe, recipeImpl sessmodels.RecipeInterface, userID string, accessTokenPayload map[string]interface{}, sessionDataInDatabase map[string]interface{}, userContext supertokens.UserContext) (sessmodels.SessionContainer, error)

func CreateNewSessionWithoutRequestResponse

func CreateNewSessionWithoutRequestResponse(tenantId string, userID string, accessTokenPayload map[string]interface{}, sessionDataInDatabase map[string]interface{}, disableAntiCSRF *bool, userContext ...supertokens.UserContext) (sessmodels.SessionContainer, error)

func FetchAndSetClaim

func FetchAndSetClaim(sessionHandle string, claim *claims.TypeSessionClaim, userContext ...supertokens.UserContext) (bool, error)

func GetAllSessionHandlesForUser

func GetAllSessionHandlesForUser(userID string, tenantId *string, userContext ...supertokens.UserContext) ([]string, error)

func GetAntiCsrfTokenFromHeaders

func GetAntiCsrfTokenFromHeaders(req *http.Request) *string

func GetAuthmodeFromHeader

func GetAuthmodeFromHeader(req *http.Request) *sessmodels.TokenTransferMethod

func GetCORSAllowedHeaders

func GetCORSAllowedHeaders() []string

func GetClaimValue

func GetClaimValue(sessionHandle string, claim *claims.TypeSessionClaim, userContext ...supertokens.UserContext) (sessmodels.GetClaimValueResult, error)

func GetCombinedJWKS

func GetCombinedJWKS() (*keyfunc.JWKS, error)

* This function fetches all JWKs from the first available core instance. This combines the other JWKS functions to become error resistant.

Every core instance a backend is connected to is expected to connect to the same database and use the same key set for token verification. Otherwise, the result of session verification would depend on which core is currently available.

func GetCookieValue

func GetCookieValue(request *http.Request, key string) *string

func GetCurrTimeInMS

func GetCurrTimeInMS() uint64

func GetJWKS

func GetJWKS(userContext ...supertokens.UserContext) (jwtmodels.GetJWKSResponse, error)

func GetRequiredClaimValidators

func GetRequiredClaimValidators(
	sessionContainer sessmodels.SessionContainer,
	overrideGlobalClaimValidators func(globalClaimValidators []claims.SessionClaimValidator, sessionContainer sessmodels.SessionContainer, userContext supertokens.UserContext) ([]claims.SessionClaimValidator, error),
	userContext supertokens.UserContext,
) ([]claims.SessionClaimValidator, error)

func GetRidFromHeader

func GetRidFromHeader(req *http.Request) *string

func GetSessionFromRequestContext

func GetSessionFromRequestContext(ctx context.Context) sessmodels.SessionContainer

func GetSessionInformation

func GetSessionInformation(sessionHandle string, userContext ...supertokens.UserContext) (*sessmodels.SessionInformation, error)

func GetSessionWithoutRequestResponse

func GetSessionWithoutRequestResponse(accessToken string, antiCSRFToken *string, options *sessmodels.VerifySessionOptions, userContext ...supertokens.UserContext) (sessmodels.SessionContainer, error)

func GetToken

func GetToken(req *http.Request, tokenType sessmodels.TokenType, transferMethod sessmodels.TokenTransferMethod) (*string, error)

func GetURLScheme

func GetURLScheme(URL string) (string, error)

func HandleRefreshAPI

func HandleRefreshAPI(apiImplementation sessmodels.APIInterface, options sessmodels.APIOptions, userContext supertokens.UserContext) error

func Init

func Init(config *sessmodels.TypeInput) supertokens.Recipe

func MakeAPIImplementation

func MakeAPIImplementation() sessmodels.APIInterface

func MergeIntoAccessTokenPayload

func MergeIntoAccessTokenPayload(sessionHandle string, accessTokenPayloadUpdate map[string]interface{}, userContext ...supertokens.UserContext) (bool, error)

func ParseJWTWithoutSignatureVerification

func ParseJWTWithoutSignatureVerification(token string) (sessmodels.ParsedJWTInfo, error)

func RefreshSession

func RefreshSession(req *http.Request, res http.ResponseWriter, userContext ...supertokens.UserContext) (sessmodels.SessionContainer, error)

func RefreshSessionWithoutRequestResponse

func RefreshSessionWithoutRequestResponse(refreshToken string, disableAntiCSRF *bool, antiCSRFToken *string, userContext ...supertokens.UserContext) (sessmodels.SessionContainer, error)

func RemoveClaim

func RemoveClaim(sessionHandle string, claim *claims.TypeSessionClaim, userContext ...supertokens.UserContext) (bool, error)

func ResetForTest

func ResetForTest()

func RevokeAllSessionsForUser

func RevokeAllSessionsForUser(userID string, tenantId *string, userContext ...supertokens.UserContext) ([]string, error)

func RevokeMultipleSessions

func RevokeMultipleSessions(sessionHandles []string, userContext ...supertokens.UserContext) ([]string, error)

func RevokeSession

func RevokeSession(sessionHandle string, userContext ...supertokens.UserContext) (bool, error)

func SetAccessTokenInResponse

func SetAccessTokenInResponse(config sessmodels.TypeNormalisedInput, res http.ResponseWriter, accessToken string, frontToken string, tokenTransferMethod sessmodels.TokenTransferMethod) error

func SetClaimValue

func SetClaimValue(sessionHandle string, claim *claims.TypeSessionClaim, value interface{}, userContext ...supertokens.UserContext) (bool, error)

func SignOutAPI

func SignOutAPI(apiImplementation sessmodels.APIInterface, options sessmodels.APIOptions, userContext supertokens.UserContext) error

func UpdateSessionDataInDatabase

func UpdateSessionDataInDatabase(sessionHandle string, newSessionData map[string]interface{}, userContext ...supertokens.UserContext) (bool, error)

func ValidateAccessTokenStructure

func ValidateAccessTokenStructure(payload map[string]interface{}, version int) error

func ValidateClaimsForSessionHandle

func ValidateClaimsForSessionHandle(
	sessionHandle string,
	overrideGlobalClaimValidators func([]claims.SessionClaimValidator, sessmodels.SessionInformation, supertokens.UserContext) []claims.SessionClaimValidator,
	userContext ...supertokens.UserContext,
) (sessmodels.ValidateClaimsResponse, error)

func ValidateClaimsInJWTPayload

func ValidateClaimsInJWTPayload(
	tenantId string,
	userID string,
	jwtPayload map[string]interface{},
	overrideGlobalClaimValidators func(globalClaimValidators []claims.SessionClaimValidator, userID string, userContext ...supertokens.UserContext) []claims.SessionClaimValidator,
	userContext ...supertokens.UserContext,
) ([]claims.ClaimValidationError, error)

func ValidateClaimsInPayload

func ValidateClaimsInPayload(claimValidators []claims.SessionClaimValidator, newAccessTokenPayload map[string]interface{}, userContext supertokens.UserContext) []claims.ClaimValidationError

func VerifySession

func VerifySession(options *sessmodels.VerifySessionOptions, otherHandler http.HandlerFunc) http.HandlerFunc

func VerifySessionHelper

func VerifySessionHelper(recipeInstance Recipe, options *sessmodels.VerifySessionOptions, otherHandler http.HandlerFunc) http.HandlerFunc

Types

type AccessTokenInfoStruct

type AccessTokenInfoStruct struct {
	SessionHandle           string
	UserID                  string
	RefreshTokenHash1       string
	ParentRefreshTokenHash1 *string
	UserData                map[string]interface{}
	AntiCsrfToken           *string
	ExpiryTime              uint64
	TimeCreated             uint64
	TenantId                string
}

func GetInfoFromAccessToken

func GetInfoFromAccessToken(jwtInfo sessmodels.ParsedJWTInfo, jwks *keyfunc.JWKS, doAntiCsrfCheck bool) (*AccessTokenInfoStruct, error)

type Recipe

type Recipe struct {
	RecipeModule supertokens.RecipeModule
	Config       sessmodels.TypeNormalisedInput
	RecipeImpl   sessmodels.RecipeInterface
	OpenIdRecipe openid.Recipe
	APIImpl      sessmodels.APIInterface
	// contains filtered or unexported fields
}

func GetRecipeInstanceOrThrowError

func GetRecipeInstanceOrThrowError() (*Recipe, error)

func MakeRecipe

func MakeRecipe(recipeId string, appInfo supertokens.NormalisedAppinfo, config *sessmodels.TypeInput, onSuperTokensAPIError func(err error, req *http.Request, res http.ResponseWriter)) (Recipe, error)

func (*Recipe) AddClaimFromOtherRecipe

func (r *Recipe) AddClaimFromOtherRecipe(claim *claims.TypeSessionClaim) error

Claim functions

func (*Recipe) AddClaimValidatorFromOtherRecipe

func (r *Recipe) AddClaimValidatorFromOtherRecipe(validator claims.SessionClaimValidator) error

func (*Recipe) GetClaimsAddedByOtherRecipes

func (r *Recipe) GetClaimsAddedByOtherRecipes() []*claims.TypeSessionClaim

type SessionContainerInput

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

type TokenInfo

type TokenInfo struct {
	Uid string      `json:"uid"`
	Ate uint64      `json:"ate"`
	Up  interface{} `json:"up"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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