Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAWSError ¶ added in v0.0.2
GetAWSError recursively checks if the error is an awserr.Error. It unwraps until it gets to the end of the error chain. A common error to look out for is cognitoidentityprovider.NotAuthorizedError. This is what you will be getting back if the refresh token has expired. For example:
var expired bool if aerr, ok := awstokens.GetAWSError(err); ok { if aerr.Code() == cognitoidentityprovider.ErrCodeNotAuthorizedException { expired = true } }
func IsNetworkError ¶ added in v0.0.3
IsNetworkError checks if a network error has occurred. The reason we can't just use `neterror.GetNetError` is because AWS errors keep the original error in a field instead of wrapping errors, so we have to the original error field too.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth contains the AWS tokens and some extra info for refreshing them.
func NewAuthWithAuthInitiator ¶
func NewAuthWithAuthInitiator(authInitiator AuthInitiator, config Config) *Auth
NewAuthWithAuthInitiator returns a pointer to an Auth using the provided config and AuthInitiator.
func (*Auth) GetAuthToken ¶
GetAuthToken returns the Access token by default, but if ShouldUseIDToken has been set to true it returns the ID token. If the token it is going to return has expired then it attempts to refresh the token before returning it.
type AuthInitiator ¶
type AuthInitiator interface {
InitiateAuth(input *cognitoidentityprovider.InitiateAuthInput) (*cognitoidentityprovider.InitiateAuthOutput, error)
}
AuthInitiator is an interface that represents the cognitoidentityprovider library client, which allows you to refresh tokens.
type Config ¶
type Config struct {
// Actual tokens
AccessToken, IDToken, RefreshToken string
// Info required to refresh the tokens
ClientID, Region string
// By default use the access token for auth, but if this is true then use ID
// token instead
ShouldUseIDToken bool
// ExpiryMargin is the margin in which a token is considered to be expired.
// If it is left empty (i.e. 0) then we will use the default value of 5
// seconds.
ExpiryMargin time.Duration
}
Config contains the initial settings for the Auth.