auth

package
v1.206.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

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

func GetApiKeyFromHeaders(headers map[string]string) string

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

func GetBearerTokenFromHeaders(headers map[string]string) string

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

func GetUserAndProviderIDFromJWTWithoutValidation(jsonWebTokenString string) (string, int64)

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

func GetUserIDFromJWTWithoutValidation(jsonWebTokenString string) string

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

func HashPassword(password string) (string, error)

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

func MaskAPIKey(key string) string

MaskAPIKey masks an API key in the form "abc***xyz"

func PasswordIsCorrect added in v1.86.0

func PasswordIsCorrect(password string, hashedPassword string) bool

PasswordIsCorrect checks whether the password is correct by validating it against the hashed password.

func RandomDigitString added in v1.135.0

func RandomDigitString(len int) string

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

func SignSessionTokenWithKey(secretKey string, sessionTokenString string) string

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.

type SessionToken added in v1.91.0

type SessionToken struct {
	IP          string    `json:"ip"`
	UserAgent   string    `json:"user_agent"`
	TimeCreated time.Time `json:"time_created"`
	Token       string    `json:"session_token"`
}

Jump to

Keyboard shortcuts

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