Documentation ¶
Index ¶
- func FindAndRemoveCurrentSessionToken(jsonWebTokenString string, secretKey string, sessionTokens []string) (string, []string)
- func GenerateJWT(payload JsonWebToken, secretKey string) (string, error)
- func GenerateJWTWithSessionToken(payload JsonWebToken, secretKey string, sessionToken string) (string, error)
- func GenerateNewApiKey() string
- func GetApiKeyFromHeaders(headers map[string]string) string
- func GetBearerTokenFromHeaders(headers map[string]string) string
- func GetSessionTokenString(request events.APIGatewayProxyRequest) (string, error)
- func GetSignedSessionTokenString(request events.APIGatewayProxyRequest, secretKey string) (string, error)
- func GetUserAndProviderIDFromJWTWithoutValidation(jsonWebTokenString string) (string, int64)
- func GetUserIDFromJWTWithoutValidation(jsonWebTokenString string) string
- func HashPassword(password string) (string, error)
- func LoginSessionWithPassword(password string, hashedPassword string, jsonWebToken JsonWebToken, ...) (string, error)
- func LoginWithPassword(password string, hashedPassword string, jsonWebToken JsonWebToken, ...) (string, error)
- func MaskAPIKey(key string) string
- func PasswordIsCorrect(password string, hashedPassword string) bool
- func RandomDigitString(len int) string
- func RandomPassword() string
- func RemoveInvalidatedAndOldSessionTokens(sessionTokens []string, invalidatedSessionToken string, age time.Duration) []string
- func SignSessionTokenWithKey(secretKey string, sessionTokenString string) string
- type JsonWebToken
- func ValidateJWT(jsonWebTokenString string, secretKey string) (JsonWebToken, error)
- func ValidateJWTWithSessionToken(jsonWebTokenString string, secretKey string, sessionToken string) (JsonWebToken, error)
- func ValidateJWTWithSessionTokens(jsonWebTokenString string, secretKey string, sessionTokens []string) (validJsonWebToken *JsonWebToken, expiredSessionToken *string)
- type SessionToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindAndRemoveCurrentSessionToken ¶ added in v1.91.0
func FindAndRemoveCurrentSessionToken(jsonWebTokenString string, secretKey string, sessionTokens []string) (string, []string)
FindAndRemoveCurrentSessionToken attempts to validate the JWT string by signing each session token using the secret, and using the resulting signed session token to validate the JWT. If the JWT is successfully validated with one of the session tokens, the session token is removed from the slice, otherwise the original session token slice is returned.
func GenerateJWT ¶ added in v1.86.0
func GenerateJWT(payload JsonWebToken, secretKey string) (string, error)
GenerateJWT takes the payload and generates a signed JWT using the provided secret
func GenerateJWTWithSessionToken ¶ added in v1.91.0
func GenerateJWTWithSessionToken(payload JsonWebToken, secretKey string, sessionToken string) (string, error)
GenerateJWTWithSessionToken first signs the session token with the secret key, then takes the payload and generates a signed JWT using the resulting signed session token
func GenerateNewApiKey ¶ added in v1.81.0
func GenerateNewApiKey() string
GenerateNewApiKey generates a 32 character API key. If the build environment is dev or stage the key will start with "dev_" or "stage_" respectively.
func GetApiKeyFromHeaders ¶ added in v1.81.0
GetApiKeyFromHeaders checks if a bearer token is passed as part of the Authorization header and returns that key. NOTE: This function is deprecated. It simply calls the more generic GetBearerTokenFromHeaders.
func GetBearerTokenFromHeaders ¶ added in v1.86.0
GetBearerTokenFromHeaders checks if a bearer token is passed as part of the Authorization header and returns that key
func GetSessionTokenString ¶ added in v1.91.0
func GetSessionTokenString(request events.APIGatewayProxyRequest) (string, error)
GetSessionTokenString creates a unique session token string from the API request.
func GetSignedSessionTokenString ¶ added in v1.91.0
func GetSignedSessionTokenString(request events.APIGatewayProxyRequest, secretKey string) (string, error)
GetSignedSessionTokenString creates a unique session token string from the API request and signs it using the secret.
func GetUserAndProviderIDFromJWTWithoutValidation ¶ added in v1.98.0
GetUserAndProviderIDFromJWTWithoutValidation gets the userID and providerID from the jsonWebTokenString without validating the signature. Successful execution of this function DOES NOT indicate that the JWT is valid in any way.
func GetUserIDFromJWTWithoutValidation ¶ added in v1.91.0
GetUserIDFromJWTWithoutValidation gets the userID from the jsonWebTokenString without validating the signature. Successful execution of this function DOES NOT indicate that the JWT is valid in any way.
func HashPassword ¶ added in v1.86.0
HashPassword returns a hashed version of the provided password.
func LoginSessionWithPassword ¶ added in v1.91.0
func LoginSessionWithPassword(password string, hashedPassword string, jsonWebToken JsonWebToken, secretKey string, sessionToken string) (string, error)
LoginSessionWithPassword checks that the provided password is correct. If the password is correct, the session token is signed using the secret key, and a JWT is returned using the signed session token
func LoginWithPassword ¶ added in v1.86.0
func LoginWithPassword(password string, hashedPassword string, jsonWebToken JsonWebToken, jwtEncryptionKey string) (string, error)
LoginWithPassword checks that the provided password is correct. If the password is correct, a signed JWT is returned using the provided encryption key.
func MaskAPIKey ¶ added in v1.84.0
MaskAPIKey masks an API key in the form "abc***xyz"
func PasswordIsCorrect ¶ added in v1.86.0
PasswordIsCorrect checks whether the password is correct by validating it against the hashed password.
func RandomDigitString ¶ added in v1.135.0
Create a pseudorandom string of digits (0-9) with specified length
func RandomPassword ¶ added in v1.135.0
func RandomPassword() string
Create a pseudorandom password consisting of two three-letter words and two digits
func RemoveInvalidatedAndOldSessionTokens ¶ added in v1.105.0
func RemoveInvalidatedAndOldSessionTokens(sessionTokens []string, invalidatedSessionToken string, age time.Duration) []string
RemoveInvalidatedAndOldSessionTokens removes the provided invalidated session token, and checks the age of the other session tokens and removes the ones that are older than the provided age.
func SignSessionTokenWithKey ¶ added in v1.91.0
SignSessionTokenWithKey signs the session token string using the secret.
Types ¶
type JsonWebToken ¶ added in v1.86.0
type JsonWebToken struct { UserID string `json:"user_id"` ProviderID int64 `json:"provider_id,omitempty"` ExpiryDate time.Time `json:"expiry_date"` }
func ValidateJWT ¶ added in v1.86.0
func ValidateJWT(jsonWebTokenString string, secretKey string) (JsonWebToken, error)
ValidateJWT parses the JWT and validates that it is signed correctly
func ValidateJWTWithSessionToken ¶ added in v1.91.0
func ValidateJWTWithSessionToken(jsonWebTokenString string, secretKey string, sessionToken string) (JsonWebToken, error)
ValidateJWTWithSessionToken first signs the session token using the secret key, then parses the JWT and validates that it is signed correctly
func ValidateJWTWithSessionTokens ¶ added in v1.91.0
func ValidateJWTWithSessionTokens(jsonWebTokenString string, secretKey string, sessionTokens []string) (validJsonWebToken *JsonWebToken, expiredSessionToken *string)
ValidateJWTWithSessionTokens attempts to validate the JWT string by signing each session token using the secret, and using the resulting signed session token to validate the JWT. If the JWT can be validated using a session token, the JsonWebToken is returned, otherwise nil is returned. If the JWT is expired, nil is returned along with the session token.