Documentation
¶
Index ¶
- func GenerateState() string
- type CognitoAdapter
- func (a *CognitoAdapter) AdminDeleteUser(ctx context.Context, username string) error
- func (a *CognitoAdapter) AdminUserGlobalSignOut(ctx context.Context, username string) error
- func (a *CognitoAdapter) ChangePassword(ctx context.Context, accessToken string, previousPassword string, ...) error
- func (a *CognitoAdapter) ClaimsFromCode(ctx context.Context, code string) (jwt.MapClaims, error)
- func (a *CognitoAdapter) ConfirmAccount(ctx context.Context, email string, code string) (bool, error)
- func (a *CognitoAdapter) DeleteUser(ctx context.Context, accessToken string) error
- func (a *CognitoAdapter) ForgotPassword(ctx context.Context, userName string) (*string, error)
- func (a *CognitoAdapter) GetUserByToken(ctx context.Context, token string) (*CognitoUser, error)
- func (a *CognitoAdapter) GetUsersByEmail(ctx context.Context, email string) ([]*CognitoUser, error)
- func (a *CognitoAdapter) GlobalSignOut(ctx context.Context, accessToken string) error
- func (a *CognitoAdapter) ListUnconfirmedUsers(ctx context.Context) ([]*CognitoUser, error)
- func (a *CognitoAdapter) OauthCodeUrl(state string) string
- func (a *CognitoAdapter) RefreshSession(ctx context.Context, refreshToken string) (*types.AuthenticationResultType, error)
- func (a *CognitoAdapter) ResendConfirmationCode(ctx context.Context, username string) error
- func (a *CognitoAdapter) ResetPassword(ctx context.Context, code string, userName string, password string) error
- func (a *CognitoAdapter) RevokeToken(ctx context.Context, refreshToken string) error
- func (a *CognitoAdapter) SignIn(ctx context.Context, email string, password string) (*types.AuthenticationResultType, error)
- func (a *CognitoAdapter) SignUp(ctx context.Context, firstName string, lastName string, email string, ...) (bool, error)
- func (a *CognitoAdapter) UpdateAttributes(ctx context.Context, username string, attributes []types.AttributeType) error
- func (a *CognitoAdapter) UpdatePassword(ctx context.Context, email string, password string) error
- type CognitoUser
- type OauthHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateState ¶ added in v0.3.2
func GenerateState() string
Types ¶
type CognitoAdapter ¶ added in v0.3.0
type CognitoAdapter struct {
// contains filtered or unexported fields
}
func New ¶ added in v0.3.0
func New(cognitoConfig configs.Cognito, region string) (*CognitoAdapter, error)
New creates a new Cognito adapter with the provided configuration. This function handles all the complex setup internally, including creating the Cognito client and OAuth handler based on whether you're using a local or production environment.
func (*CognitoAdapter) AdminDeleteUser ¶ added in v0.4.0
func (a *CognitoAdapter) AdminDeleteUser(ctx context.Context, username string) error
AdminDeleteUser deletes a user from the Cognito User Pool by username using admin credentials. Use this for server-side cleanup where no user access token is available (e.g., removing unconfirmed users). Only removes the user from the pool — unconfirmed users are not persisted in the application DB.
func (*CognitoAdapter) AdminUserGlobalSignOut ¶ added in v0.11.0
func (a *CognitoAdapter) AdminUserGlobalSignOut(ctx context.Context, username string) error
AdminUserGlobalSignOut signs a pool user out of every device: Cognito stops accepting the user's refresh tokens, and their access tokens on its own user-pool operations. A service that verifies an access or ID token itself accepts it until it expires. It runs on admin credentials, so unlike GlobalSignOut it needs no token from the user. It leaves the managed login session cookie in place.
The caller's IAM role needs cognito-idp:AdminUserGlobalSignOut on the pool. A missing user returns an error wrapping ErrNotFound, and throttling one wrapping ErrTooManyRequests. Errors leave out the username, which may be an email address.
func (*CognitoAdapter) ChangePassword ¶ added in v0.6.1
func (a *CognitoAdapter) ChangePassword(ctx context.Context, accessToken string, previousPassword string, proposedPassword string) error
ChangePassword changes a signed-in user's own password, verifying the previous one. Self-service via the user's access token, so Cognito enforces the password policy and any reuse rules — unlike UpdatePassword, which sets a password with admin privilege. Use this for a "change password" flow; use UpdatePassword only for an admin reset with no current password.
func (*CognitoAdapter) ClaimsFromCode ¶ added in v0.3.0
func (*CognitoAdapter) ConfirmAccount ¶ added in v0.3.0
func (*CognitoAdapter) DeleteUser ¶ added in v0.3.0
func (a *CognitoAdapter) DeleteUser(ctx context.Context, accessToken string) error
DeleteUser deletes the user from the Cognito User Pool using their access token. Use this only for user-initiated flows where the user is logged in (e.g., "Delete my account"). The pool is inferred from the token. Only removes the user from the pool, not any application data. Not suitable for batch cleanup — use AdminDeleteUser instead, which only requires a username.
func (*CognitoAdapter) ForgotPassword ¶ added in v0.3.0
func (*CognitoAdapter) GetUserByToken ¶ added in v0.3.0
func (a *CognitoAdapter) GetUserByToken(ctx context.Context, token string) (*CognitoUser, error)
func (*CognitoAdapter) GetUsersByEmail ¶ added in v0.3.0
func (a *CognitoAdapter) GetUsersByEmail(ctx context.Context, email string) ([]*CognitoUser, error)
func (*CognitoAdapter) GlobalSignOut ¶ added in v0.6.2
func (a *CognitoAdapter) GlobalSignOut(ctx context.Context, accessToken string) error
GlobalSignOut revokes every access and refresh token issued to the user identified by accessToken, signing them out of all devices. Use it to invalidate other sessions after a password change: the caller re-signs-in afterward to mint a fresh session that survives the revocation.
accessToken authorizes the call, so a rejected token surfaces as ErrPermissionDenied rather than success: unlike revoking a single token, a rejected credential here means Cognito revoked nothing and the other sessions live on. Pass a freshly minted token and retry on that error.
func (*CognitoAdapter) ListUnconfirmedUsers ¶ added in v0.4.0
func (a *CognitoAdapter) ListUnconfirmedUsers(ctx context.Context) ([]*CognitoUser, error)
func (*CognitoAdapter) OauthCodeUrl ¶ added in v0.3.0
func (a *CognitoAdapter) OauthCodeUrl(state string) string
func (*CognitoAdapter) RefreshSession ¶ added in v0.4.3
func (a *CognitoAdapter) RefreshSession(ctx context.Context, refreshToken string) (*types.AuthenticationResultType, error)
RefreshSession exchanges a valid refresh token for new access and ID tokens via the Cognito REFRESH_TOKEN_AUTH flow. The result carries a fresh AccessToken/IdToken and ExpiresIn; the refresh token itself is unchanged (Cognito does not reissue it in this flow).
func (*CognitoAdapter) ResendConfirmationCode ¶ added in v0.3.0
func (a *CognitoAdapter) ResendConfirmationCode(ctx context.Context, username string) error
func (*CognitoAdapter) ResetPassword ¶ added in v0.3.0
func (*CognitoAdapter) RevokeToken ¶ added in v0.4.3
func (a *CognitoAdapter) RevokeToken(ctx context.Context, refreshToken string) error
RevokeToken revokes a refresh token and every access token issued from it, backing server-side logout. Revoking an already-invalid token is treated as success so logout stays idempotent. The app client must have token revocation enabled.
func (*CognitoAdapter) SignIn ¶ added in v0.3.0
func (a *CognitoAdapter) SignIn(ctx context.Context, email string, password string) (*types.AuthenticationResultType, error)
func (*CognitoAdapter) UpdateAttributes ¶ added in v0.3.0
func (a *CognitoAdapter) UpdateAttributes(ctx context.Context, username string, attributes []types.AttributeType) error
func (*CognitoAdapter) UpdatePassword ¶ added in v0.3.0
type CognitoUser ¶ added in v0.3.0
type CognitoUser struct {
Username string
Email string
EmailVerified bool
GivenName string
FamilyName string
PhoneNumber string
// Cognito account status, e.g. CONFIRMED or EXTERNAL_PROVIDER. A federated account that has never
// been given a password reports EXTERNAL_PROVIDER, so this tells apart the accounts that can
// authenticate with a password from those that cannot. Only ListUsers reports it; GetUser does not.
Status string
CreatedAt *time.Time
}
type OauthHandler ¶
type OauthHandler struct {
// contains filtered or unexported fields
}
func NewCognitoOauthHandler ¶ added in v0.2.6
func NewCognitoOauthHandler(cognitoConfig configs.Cognito, scopes []string) (*OauthHandler, error)
NewCognitoOauthHandler is a wrapper on NewOauthHandler that uses the CognitoConfig for most of the variables.
func NewOauthHandler ¶
func NewOauthHandler(clientId string, clientSecret string, redirectUrl string, issuerUrl string, scopes []string) (*OauthHandler, error)
NewOauthHandler creates a handler that is meant to operate between oidc and oauth to handle the necessary redirects and issuer interactions. This has been tested against Cognito specifically.
func (*OauthHandler) AuthCodeUrl ¶
func (h *OauthHandler) AuthCodeUrl(state string, opts ...oauth2.AuthCodeOption) string
func (*OauthHandler) ExchangeCode ¶
func (*OauthHandler) Verifier ¶
func (h *OauthHandler) Verifier() *oidc.IDTokenVerifier