services

package
v0.0.0-...-3beece8 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2018 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidToken is a general token error
	ErrInvalidToken = errors.New("Invalid Token")
	ErrExpiredToken = errors.New("Token has expired")
	ErrUsageToken   = errors.New("Token usage is wrong: neither id nor access")
	ErrParsingToken = errors.New("Unable to parse token")
)

Functions

This section is empty.

Types

type AWSCognito

type AWSCognito interface {
	Init() error
	SecretHash(string) string
	SignUp(string, string, string, string) (*cogIdp.SignUpOutput, error)
	SignIn(string, string) (*cogIdp.InitiateAuthOutput, error)
	GetUser(string) (*cogIdp.AdminGetUserOutput, error)
	ConfirmSignUp(string) (*cogIdp.ConfirmSignUpOutput, error)
	ValidateToken(string, map[string]JWKKey) error
	ForgotPassword(string) (*cogIdp.ForgotPasswordOutput, error)
	ConfirmForgotPassword(string, string, string) (*cogIdp.ConfirmForgotPasswordOutput, error)
	ChangePassword(string, string, string) (*cogIdp.ChangePasswordOutput, error)
}

AWSCognito methods interface

type CognitoClient

type CognitoClient struct{}

* see Using ID Tokens and Access Tokens in your Web APIs: https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-with-identity-providers.html

decode and verify the sitnature of Cognito JSON web key token: https://aws.amazon.com/premiumsupport/knowledge-center/decode-verify-cognito-json-token/

verify token example: https://github.com/mura123yasu/go-cognito/blob/master/verifyToken.go

Email and phone verification: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-email-phone-verification.html

CognitoClient is an empty structure

func (*CognitoClient) ChangePassword

func (c *CognitoClient) ChangePassword(accessToken, prevPass, newPass string) (*cogIdp.ChangePasswordOutput, error)

ChangePassword resets password for the user (a link to their email)

func (*CognitoClient) ConfirmForgotPassword

func (c *CognitoClient) ConfirmForgotPassword(newPass, code, username string) (*cogIdp.ConfirmForgotPasswordOutput, error)

ConfirmForgotPassword

func (*CognitoClient) ConfirmSignUp

func (c *CognitoClient) ConfirmSignUp(code, username string) (*cogIdp.ConfirmSignUpOutput, error)

ConfirmSignUp confirms user registration link sent to their email

func (*CognitoClient) ForgotPassword

func (c *CognitoClient) ForgotPassword(username string) (*cogIdp.ForgotPasswordOutput, error)

ForgotPassword requires custom_message in Cognito with a Lambda function to custom link with username and confirm code

func (*CognitoClient) GetUser

func (c *CognitoClient) GetUser(username string) (*cogIdp.AdminGetUserOutput, error)

* output: {"level":"info","msg":"output from getting user: %v\n{\n Enabled: true,\n UserAttributes: [{\n Name: \"sub\",\n Value: \"b6e60099-4efa-4b37-a799-d82e314a71e9\"\n },{\n Name: \"email_verified\",\n Value: \"false\"\n },{\n Name: \"email\",\n Value: \"gwang81@gmail.com\"\n }],\n UserCreateDate: 2018-02-20 05:46:17 +0000 UTC,\n UserLastModifiedDate: 2018-02-20 05:46:17 +0000 UTC,\n UserStatus: \"UNCONFIRMED\",\n Username: \"gwang81\"\n}","time":"2018-02-19T22:10:48-08:00"}

func (*CognitoClient) Init

func (c *CognitoClient) Init() error

Init initializes all the variables as well as the jwk

func (*CognitoClient) SecretHash

func (c *CognitoClient) SecretHash(username string) string

SecretHash is for generating secret hash specific to username

func (*CognitoClient) SignIn

func (c *CognitoClient) SignIn(username, password string) (*cogIdp.InitiateAuthOutput, error)

func (*CognitoClient) SignUp

func (c *CognitoClient) SignUp(username, password, confirmPass, email string) (*cogIdp.SignUpOutput, error)

SignUp registers a user given the username info

func (*CognitoClient) ValidateToken

func (c *CognitoClient) ValidateToken(tokenStr string) (models.AuthenticatedUser, error)

ValidateToken validates the token provided by client

type JWK

type JWK struct {
	Keys []JWKKey
}

JWK is json data struct for JSON Web Key

type JWKKey

type JWKKey struct {
	Alg string
	E   string
	Kid string
	Kty string
	N   string
	Use string
}

JWKKey is JSON web key specific for the cognito region and userpoolId

Jump to

Keyboard shortcuts

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