auth

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

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) 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 (a *CognitoAdapter) ClaimsFromCode(ctx context.Context, code string) (jwt.MapClaims, error)

func (*CognitoAdapter) ConfirmAccount added in v0.3.0

func (a *CognitoAdapter) ConfirmAccount(ctx context.Context, email string, code string) (bool, error)

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 (a *CognitoAdapter) ForgotPassword(ctx context.Context, userName string) (*string, error)

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 (a *CognitoAdapter) ResetPassword(ctx context.Context, code string, userName string, password string) error

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) SignUp added in v0.3.0

func (a *CognitoAdapter) SignUp(ctx context.Context, firstName string, lastName string, email string, password string) (bool, 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

func (a *CognitoAdapter) UpdatePassword(ctx context.Context, email string, password string) error

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 (h *OauthHandler) ExchangeCode(ctx context.Context, code string) (*oauth2.Token, error)

func (*OauthHandler) Verifier

func (h *OauthHandler) Verifier() *oidc.IDTokenVerifier

Jump to

Keyboard shortcuts

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