sessmodels

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: 6 Imported by: 0

Documentation

Index

Constants

View Source
const SessionContext int = iota

Variables

This section is empty.

Functions

This section is empty.

Types

type APIInterface

type APIInterface struct {
	RefreshPOST   *func(options APIOptions, userContext supertokens.UserContext) (SessionContainer, error)
	SignOutPOST   *func(sessionContainer SessionContainer, options APIOptions, userContext supertokens.UserContext) (SignOutPOSTResponse, error)
	VerifySession *func(verifySessionOptions *VerifySessionOptions, options APIOptions, userContext supertokens.UserContext) (SessionContainer, error)
}

*

  • We do not add a GeneralErrorResponse response to the refresh API
  • since it's not something that is directly called by the user on the
  • frontend anyway

type APIOptions

type APIOptions struct {
	RecipeImplementation RecipeInterface
	Config               TypeNormalisedInput
	RecipeID             string
	Req                  *http.Request
	Res                  http.ResponseWriter
	OtherHandler         http.HandlerFunc

	ClaimValidatorsAddedByOtherRecipes []claims.SessionClaimValidator
}

type CreateOrRefreshAPIResponse

type CreateOrRefreshAPIResponse struct {
	Session       SessionStruct                   `json:"session"`
	AccessToken   CreateOrRefreshAPIResponseToken `json:"accessToken"`
	RefreshToken  CreateOrRefreshAPIResponseToken `json:"refreshToken"`
	AntiCsrfToken *string                         `json:"antiCsrfToken"`
}

type CreateOrRefreshAPIResponseToken

type CreateOrRefreshAPIResponseToken struct {
	Token       string `json:"token"`
	Expiry      uint64 `json:"expiry"`
	CreatedTime uint64 `json:"createdTime"`
}

type ErrorHandlers

type ErrorHandlers struct {
	OnUnauthorised       func(message string, req *http.Request, res http.ResponseWriter) error
	OnTokenTheftDetected func(sessionHandle string, userID string, req *http.Request, res http.ResponseWriter) error
	OnInvalidClaim       func(validationErrors []claims.ClaimValidationError, req *http.Request, res http.ResponseWriter) error
}

type GetClaimValueResult

type GetClaimValueResult struct {
	OK *struct {
		Value interface{}
	}
	SessionDoesNotExistError *struct{}
}

type GetJWKSFunction

type GetJWKSFunction = func(string) GetJWKSResult

type GetJWKSFunctionObject

type GetJWKSFunctionObject struct {
	Fn   GetJWKSFunction
	Path string
}

type GetJWKSResult

type GetJWKSResult struct {
	JWKS        *keyfunc.JWKS
	Error       error
	LastFetched int64
}

type GetSessionResponse

type GetSessionResponse struct {
	Status      string
	Session     SessionStruct                   `json:"session"`
	AccessToken CreateOrRefreshAPIResponseToken `json:"accessToken"`
}

type JWTNormalisedConfig

type JWTNormalisedConfig struct {
	Issuer                           *string
	Enable                           bool
	PropertyNameInAccessTokenPayload string
}

type KeyInfo

type KeyInfo struct {
	PublicKey  string
	ExpiryTime uint64
	CreatedAt  uint64
}

type NormalisedErrorHandlers

type NormalisedErrorHandlers struct {
	OnUnauthorised       func(message string, req *http.Request, res http.ResponseWriter) error
	OnTryRefreshToken    func(message string, req *http.Request, res http.ResponseWriter) error
	OnTokenTheftDetected func(sessionHandle string, userID string, req *http.Request, res http.ResponseWriter) error
	OnInvalidClaim       func(validationErrors []claims.ClaimValidationError, req *http.Request, res http.ResponseWriter) error
}

type OverrideStruct

type OverrideStruct struct {
	Functions     func(originalImplementation RecipeInterface) RecipeInterface
	APIs          func(originalImplementation APIInterface) APIInterface
	OpenIdFeature *openidmodels.OverrideStruct
}

type ParsedJWTInfo

type ParsedJWTInfo struct {
	RawTokenString string
	RawPayload     string
	Header         string
	Payload        map[string]interface{}
	Signature      string
	Version        int
	KID            *string
}

type RecipeInterface

type RecipeInterface struct {
	CreateNewSession            *func(userID string, accessTokenPayload map[string]interface{}, sessionDataInDatabase map[string]interface{}, disableAntiCsrf *bool, tenantId string, userContext supertokens.UserContext) (SessionContainer, error)
	GetSession                  *func(accessToken *string, antiCSRFToken *string, options *VerifySessionOptions, userContext supertokens.UserContext) (SessionContainer, error)
	RefreshSession              *func(refreshToken string, antiCSRFToken *string, disableAntiCSRF bool, userContext supertokens.UserContext) (SessionContainer, error)
	GetSessionInformation       *func(sessionHandle string, userContext supertokens.UserContext) (*SessionInformation, error)
	RevokeAllSessionsForUser    *func(userID string, tenantId string, revokeAcrossAllTenants *bool, userContext supertokens.UserContext) ([]string, error)
	GetAllSessionHandlesForUser *func(userID string, tenantId string, fetchAcrossAllTenants *bool, userContext supertokens.UserContext) ([]string, error)
	RevokeSession               *func(sessionHandle string, userContext supertokens.UserContext) (bool, error)
	RevokeMultipleSessions      *func(sessionHandles []string, userContext supertokens.UserContext) ([]string, error)
	UpdateSessionDataInDatabase *func(sessionHandle string, newSessionData map[string]interface{}, userContext supertokens.UserContext) (bool, error)
	MergeIntoAccessTokenPayload *func(sessionHandle string, accessTokenPayloadUpdate map[string]interface{}, userContext supertokens.UserContext) (bool, error)
	RegenerateAccessToken       *func(accessToken string, newAccessTokenPayload *map[string]interface{}, userContext supertokens.UserContext) (*RegenerateAccessTokenResponse, error)

	GetGlobalClaimValidators   *func(userId string, claimValidatorsAddedByOtherRecipes []claims.SessionClaimValidator, tenantId string, userContext supertokens.UserContext) ([]claims.SessionClaimValidator, error)
	ValidateClaims             *func(userId string, accessTokenPayload map[string]interface{}, claimValidators []claims.SessionClaimValidator, userContext supertokens.UserContext) (ValidateClaimsResult, error)
	ValidateClaimsInJWTPayload *func(userId string, jwtPayload map[string]interface{}, claimValidators []claims.SessionClaimValidator, userContext supertokens.UserContext) ([]claims.ClaimValidationError, error)
	FetchAndSetClaim           *func(sessionHandle string, claim *claims.TypeSessionClaim, userContext supertokens.UserContext) (bool, error)
	SetClaimValue              *func(sessionHandle string, claim *claims.TypeSessionClaim, value interface{}, userContext supertokens.UserContext) (bool, error)
	GetClaimValue              *func(sessionHandle string, claim *claims.TypeSessionClaim, userContext supertokens.UserContext) (GetClaimValueResult, error)
	RemoveClaim                *func(sessionHandle string, claim *claims.TypeSessionClaim, userContext supertokens.UserContext) (bool, error)
}

type RegenerateAccessTokenResponse

type RegenerateAccessTokenResponse struct {
	Status      string                          `json:"status"`
	Session     SessionStruct                   `json:"session"`
	AccessToken CreateOrRefreshAPIResponseToken `json:"accessToken"`
}

type RequestResponseInfo

type RequestResponseInfo struct {
	Res                 http.ResponseWriter
	Req                 *http.Request
	TokenTransferMethod TokenTransferMethod
}

type SessionContainer

type SessionContainer = *TypeSessionContainer

type SessionInformation

type SessionInformation struct {
	SessionHandle                    string
	UserId                           string
	SessionDataInDatabase            map[string]interface{}
	Expiry                           uint64
	CustomClaimsInAccessTokenPayload map[string]interface{}
	TimeCreated                      uint64
	TenantId                         string
}

type SessionStruct

type SessionStruct struct {
	Handle                string                 `json:"handle"`
	UserID                string                 `json:"userId"`
	UserDataInAccessToken map[string]interface{} `json:"userDataInJWT"`
	ExpiryTime            uint64                 `json:"expiryTime"`
	TenantId              string                 `json:"tenantId"`
}

type SessionTokens

type SessionTokens struct {
	AccessToken                   string
	RefreshToken                  *string
	AntiCsrfToken                 *string
	FrontToken                    string
	AccessAndFrontendTokenUpdated bool
}

type SignOutPOSTResponse

type SignOutPOSTResponse struct {
	OK           *struct{}
	GeneralError *supertokens.GeneralErrorResponse
}

type TokenTransferMethod

type TokenTransferMethod string

When adding a new token transfer method, it's also necessary to update the related constant (availableTokenTransferMethods) in `session/constants.go`

const (
	CookieTransferMethod TokenTransferMethod = "cookie"
	HeaderTransferMethod TokenTransferMethod = "header"
	AnyTransferMethod    TokenTransferMethod = "any"
)

type TokenType

type TokenType string
const (
	AccessToken  TokenType = "access"
	RefreshToken TokenType = "refresh"
)

type TypeInput

type TypeInput struct {
	CookieSecure                                 *bool
	CookieSameSite                               *string
	SessionExpiredStatusCode                     *int
	InvalidClaimStatusCode                       *int
	CookieDomain                                 *string
	AntiCsrf                                     *string
	Override                                     *OverrideStruct
	ErrorHandlers                                *ErrorHandlers
	GetTokenTransferMethod                       func(req *http.Request, forCreateNewSession bool, userContext supertokens.UserContext) TokenTransferMethod
	ExposeAccessTokenToFrontendInCookieBasedAuth bool
	UseDynamicAccessTokenSigningKey              *bool
}

type TypeNormalisedInput

type TypeNormalisedInput struct {
	RefreshTokenPath                             supertokens.NormalisedURLPath
	CookieDomain                                 *string
	CookieSameSite                               string
	CookieSecure                                 bool
	SessionExpiredStatusCode                     int
	InvalidClaimStatusCode                       int
	AntiCsrf                                     string
	Override                                     OverrideStruct
	ErrorHandlers                                NormalisedErrorHandlers
	GetTokenTransferMethod                       func(req *http.Request, forCreateNewSession bool, userContext supertokens.UserContext) TokenTransferMethod
	ExposeAccessTokenToFrontendInCookieBasedAuth bool
	UseDynamicAccessTokenSigningKey              bool
}

type TypeSessionContainer

type TypeSessionContainer struct {
	RevokeSession                  func() error
	GetSessionDataInDatabase       func() (map[string]interface{}, error)
	UpdateSessionDataInDatabase    func(newSessionData map[string]interface{}) error
	GetUserID                      func() string
	GetTenantId                    func() string
	GetAccessTokenPayload          func() map[string]interface{}
	GetHandle                      func() string
	GetAllSessionTokensDangerously func() SessionTokens
	GetAccessToken                 func() string
	GetTimeCreated                 func() (uint64, error)
	GetExpiry                      func() (uint64, error)

	RevokeSessionWithContext               func(userContext supertokens.UserContext) error
	GetSessionDataInDatabaseWithContext    func(userContext supertokens.UserContext) (map[string]interface{}, error)
	UpdateSessionDataInDatabaseWithContext func(newSessionData map[string]interface{}, userContext supertokens.UserContext) error
	GetUserIDWithContext                   func(userContext supertokens.UserContext) string
	GetTenantIdWithContext                 func(userContext supertokens.UserContext) string
	GetAccessTokenPayloadWithContext       func(userContext supertokens.UserContext) map[string]interface{}
	GetHandleWithContext                   func(userContext supertokens.UserContext) string
	GetAccessTokenWithContext              func(userContext supertokens.UserContext) string
	GetTimeCreatedWithContext              func(userContext supertokens.UserContext) (uint64, error)
	GetExpiryWithContext                   func(userContext supertokens.UserContext) (uint64, error)

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

	AssertClaimsWithContext     func(claimValidators []claims.SessionClaimValidator, userContext supertokens.UserContext) error
	FetchAndSetClaimWithContext func(claim *claims.TypeSessionClaim, userContext supertokens.UserContext) error
	SetClaimValueWithContext    func(claim *claims.TypeSessionClaim, value interface{}, userContext supertokens.UserContext) error
	GetClaimValueWithContext    func(claim *claims.TypeSessionClaim, userContext supertokens.UserContext) interface{}
	RemoveClaimWithContext      func(claim *claims.TypeSessionClaim, userContext supertokens.UserContext) error

	MergeIntoAccessTokenPayload func(accessTokenPayloadUpdate map[string]interface{}) error

	AssertClaims            func(claimValidators []claims.SessionClaimValidator) error
	FetchAndSetClaim        func(claim *claims.TypeSessionClaim) error
	SetClaimValue           func(claim *claims.TypeSessionClaim, value interface{}) error
	GetClaimValue           func(claim *claims.TypeSessionClaim) interface{}
	RemoveClaim             func(claim *claims.TypeSessionClaim) error
	AttachToRequestResponse func(info RequestResponseInfo) error
}

type ValidateClaimsResponse

type ValidateClaimsResponse struct {
	OK *struct {
		InvalidClaims []claims.ClaimValidationError
	}
	SessionDoesNotExistError *struct{}
}

type ValidateClaimsResult

type ValidateClaimsResult struct {
	InvalidClaims            []claims.ClaimValidationError
	AccessTokenPayloadUpdate map[string]interface{}
}

type VerifySessionOptions

type VerifySessionOptions struct {
	AntiCsrfCheck                 *bool
	SessionRequired               *bool
	CheckDatabase                 *bool
	OverrideGlobalClaimValidators func(globalClaimValidators []claims.SessionClaimValidator, sessionContainer SessionContainer, userContext supertokens.UserContext) ([]claims.SessionClaimValidator, error)
}

Jump to

Keyboard shortcuts

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