models

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

View Source
const (
	BodyReadError              = "RequestBodyReadError"
	JSONMarshalError           = "JSONMarshalError"
	JSONUnmarshalError         = "JSONUnmarshalError"
	WriteResponseError         = "WriteResponseError"
	InvalidForenameError       = "InvalidForename"
	InvalidSurnameError        = "InvalidSurname"
	InvalidEmailError          = "InvalidEmail"
	InvalidTokenError          = "InvalidToken"
	InternalError              = "InternalServerError"
	NotFoundError              = "NotFound"
	AlreadyExistsError         = "AlreadyExists"
	DeliveryFailureError       = "DeliveryFailure"
	InvalidCodeError           = "InvalidCode"
	ExpiredCodeError           = "ExpiredCode"
	InvalidFieldError          = "InvalidField"
	InvalidPasswordError       = "InvalidPassword"
	LimitExceededError         = "LimitExceeded"
	NotAuthorisedError         = "NotAuthorised"
	PasswordResetRequiredError = "PasswordResetRequired"
	TooManyFailedAttemptsError = "TooManyFailedAttempts"
	TooManyRequestsError       = "TooManyRequests"
	UserNotConfirmedError      = "UserNotConfirmed"
	UsernameExistsError        = "UsernameExists"
	MissingConfigError         = "MissingConfig"
)

API error codes

View Source
const (
	MissingAuthorizationTokenDescription   = "no Authorization token was provided"
	MissingRefreshTokenDescription         = "no Refresh token was provided"
	MissingIDTokenDescription              = "no ID token was provided"
	MalformedIDTokenDescription            = "the ID token could not be parsed"
	MalformedAuthorizationTokenDescription = "the authorization token does not meet the required format"
	ErrorMarshalFailedDescription          = "failed to marshal the error"
	ErrorUnmarshalFailedDescription        = "failed to unmarshal the request body"
	WriteResponseFailedDescription         = "failed to write http response"
	CastingAWSErrorFailedDescription       = "failed to cast error to AWS error"
	UnrecognisedCognitoResponseDescription = "unexpected response from cognito"
	BodyReadFailedDescription              = "endpoint returned an error reading the request body"
	InvalidPasswordDescription             = "the submitted password could not be validated"
	PasswordGenerationErrorDescription     = "failed to generate a valid password"
	InvalidForenameErrorDescription        = "the submitted user's forename could not be validated"
	InvalidSurnameErrorDescription         = "the submitted user's surname could not be validated"
	InvalidEmailDescription                = "the submitted email could not be validated"
	DuplicateEmailDescription              = "account using email address found"
	SignInFailedDescription                = "Incorrect username or password"
	SignInAttemptsExceededDescription      = "Password attempts exceeded"
	MissingConfigDescription               = "required configuration setting is missing"
)

API error descriptions

Variables

View Source
var CognitoErrorMapping = map[string]string{
	cognitoidentityprovider.ErrCodeInternalErrorException:          InternalError,
	cognitoidentityprovider.ErrCodeCodeDeliveryFailureException:    DeliveryFailureError,
	cognitoidentityprovider.ErrCodeCodeMismatchException:           InvalidCodeError,
	cognitoidentityprovider.ErrCodeConcurrentModificationException: InternalError,
	cognitoidentityprovider.ErrCodeExpiredCodeException:            ExpiredCodeError,
	cognitoidentityprovider.ErrCodeGroupExistsException:            AlreadyExistsError,
	cognitoidentityprovider.ErrCodeInvalidOAuthFlowException:       InternalError,
	cognitoidentityprovider.ErrCodeInvalidParameterException:       InvalidFieldError,
	cognitoidentityprovider.ErrCodeInvalidPasswordException:        InvalidPasswordError,
	cognitoidentityprovider.ErrCodeLimitExceededException:          LimitExceededError,
	cognitoidentityprovider.ErrCodeNotAuthorizedException:          NotAuthorisedError,
	cognitoidentityprovider.ErrCodePasswordResetRequiredException:  PasswordResetRequiredError,
	cognitoidentityprovider.ErrCodeResourceNotFoundException:       NotFoundError,
	cognitoidentityprovider.ErrCodeTooManyFailedAttemptsException:  TooManyFailedAttemptsError,
	cognitoidentityprovider.ErrCodeTooManyRequestsException:        TooManyRequestsError,
	cognitoidentityprovider.ErrCodeUserNotConfirmedException:       UserNotConfirmedError,
	cognitoidentityprovider.ErrCodeUserNotFoundException:           NotFoundError,
	cognitoidentityprovider.ErrCodeUsernameExistsException:         UsernameExistsError,
	request.ErrCodeSerialization:                                   InternalError,
	request.ErrCodeRead:                                            InternalError,
	request.ErrCodeResponseTimeout:                                 InternalError,
	request.ErrCodeInvalidPresignExpire:                            InternalError,
	request.CanceledErrorCode:                                      InternalError,
	request.ErrCodeRequestError:                                    InternalError,
}

Mapping Cognito error codes to API error codes

Functions

func MapCognitoErrorToLocalError added in v1.8.0

func MapCognitoErrorToLocalError(ctx context.Context, cognitoErr awserr.Error) string

Types

type AccessToken added in v1.8.0

type AccessToken struct {
	AuthHeader  string
	TokenString string
}

func (*AccessToken) GenerateSignOutRequest added in v1.8.0

func (t *AccessToken) GenerateSignOutRequest() *cognitoidentityprovider.GlobalSignOutInput

func (*AccessToken) Validate added in v1.8.0

func (t *AccessToken) Validate(ctx context.Context) *Error

type CreateUserInput

type CreateUserInput struct {
	UserInput *cognitoidentityprovider.AdminCreateUserInput
}

type CreateUserOutput

type CreateUserOutput struct {
	UserOutput *cognitoidentityprovider.AdminCreateUserOutput
}

type Error added in v1.8.0

type Error struct {
	Cause       error  `json:"-"`
	Code        string `json:"code"`
	Description string `json:"description"`
}

func NewCognitoError added in v1.8.0

func NewCognitoError(ctx context.Context, err error, errContext string) *Error

func NewError added in v1.8.0

func NewError(ctx context.Context, cause error, code string, description string) *Error

func NewValidationError added in v1.8.0

func NewValidationError(ctx context.Context, code string, description string) *Error

func (*Error) Error added in v1.8.0

func (e *Error) Error() string

type ErrorResponse added in v1.8.0

type ErrorResponse struct {
	Errors []error `json:"errors"`
	Status int     `json:"-"`
}

func NewErrorResponse added in v1.8.0

func NewErrorResponse(errors []error, statusCode int) *ErrorResponse

type IdClaims

type IdClaims struct {
	Sub           string `json:"sub"`
	Aud           string `json:"aud"`
	EmailVerified bool   `json:"email_verified"`
	TokenUse      string `json:"token_use"`
	AuthTime      int    `json:"auth_time"`
	Iss           string `json:"iss"`
	CognitoUser   string `json:"cognito:username"`
	Exp           int    `json:"exp"`
	GivenName     string `json:"given_name"`
	Iat           int    `json:"iat"`
	Email         string `json:"email"`
	jwt.StandardClaims
}

type IdToken

type IdToken struct {
	TokenString string
	Claims      IdClaims
}

func (*IdToken) ParseWithoutValidating

func (t *IdToken) ParseWithoutValidating(ctx context.Context, tokenString string) *Error

ParseWithoutValidating parses the claims in an ID token JWT in to a IdClaims struct without validating the token

func (*IdToken) Validate

func (t *IdToken) Validate(ctx context.Context) *Error

Validate validates the existence of a JWT string and that it is correctly formatting, storing the tokens claims in an IdClaims struct

type ListUsersInput

type ListUsersInput struct {
	ListUsersInput *cognitoidentityprovider.ListUsersInput
}

type ListUsersOutput

type ListUsersOutput struct {
	ListUsersOutput *cognitoidentityprovider.ListUsersOutput
}

type RefreshToken

type RefreshToken struct {
	TokenString string
}

func (*RefreshToken) BuildSuccessfulJsonResponse added in v1.8.0

func (t *RefreshToken) BuildSuccessfulJsonResponse(ctx context.Context, result *cognitoidentityprovider.InitiateAuthOutput) ([]byte, error)

func (*RefreshToken) GenerateRefreshRequest

func (t *RefreshToken) GenerateRefreshRequest(clientSecret string, username string, clientId string) *cognitoidentityprovider.InitiateAuthInput

GenerateRefreshRequest produces a Cognito InitiateAuthInput struct for refreshing a users current session

func (*RefreshToken) Validate

func (t *RefreshToken) Validate(ctx context.Context) *Error

Validate validates the existence of a JWT string

type SuccessResponse added in v1.8.0

type SuccessResponse struct {
	Body   []byte `json:"-"`
	Status int    `json:"-"`
}

func NewSuccessResponse added in v1.8.0

func NewSuccessResponse(jsonBody []byte, statusCode int) *SuccessResponse

type UserParams

type UserParams struct {
	Forename string `json:"forename"`
	Surname  string `json:"surname"`
	Email    string `json:"email"`
	Password string `json:"-"`
}

func (UserParams) BuildCreateUserRequest added in v1.8.0

func (p UserParams) BuildCreateUserRequest(userId string, userPoolId string) *cognitoidentityprovider.AdminCreateUserInput

func (UserParams) BuildListUserRequest added in v1.8.0

func (p UserParams) BuildListUserRequest(filterString string, requiredAttribute string, limit int64, userPoolId *string) *cognitoidentityprovider.ListUsersInput

func (UserParams) BuildSuccessfulJsonResponse added in v1.8.0

func (p UserParams) BuildSuccessfulJsonResponse(ctx context.Context, createdUser *cognitoidentityprovider.AdminCreateUserOutput) ([]byte, error)

func (UserParams) CheckForDuplicateEmail added in v1.8.0

func (p UserParams) CheckForDuplicateEmail(ctx context.Context, listUserResp *cognitoidentityprovider.ListUsersOutput) error

func (UserParams) GeneratePassword added in v1.8.0

func (p UserParams) GeneratePassword(ctx context.Context) error

func (UserParams) ValidateRegistration added in v1.8.0

func (p UserParams) ValidateRegistration(ctx context.Context) []error

type UserSignIn added in v1.8.0

type UserSignIn struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

func (*UserSignIn) BuildCognitoRequest added in v1.8.0

func (p *UserSignIn) BuildCognitoRequest(clientId string, clientSecret string, clientAuthFlow string) *cognitoidentityprovider.InitiateAuthInput

func (*UserSignIn) BuildSuccessfulJsonResponse added in v1.8.0

func (p *UserSignIn) BuildSuccessfulJsonResponse(ctx context.Context, result *cognitoidentityprovider.InitiateAuthOutput) ([]byte, error)

func (*UserSignIn) ValidateCredentials added in v1.8.0

func (p *UserSignIn) ValidateCredentials(ctx context.Context) *[]error

Jump to

Keyboard shortcuts

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