postconfirmation

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package postconfirmation implements the PostConfirmation hook. It runs after a user confirms their sign-up or resets their password, and carries out the actions its optional policy returns. By default (password.replace) it replaces the password of each native user with a random one that nobody knows, so the user can only sign in with passwordless factors such as email or SMS one-time passwords and passkeys.

Index

Constants

View Source
const (
	// TriggerConfirmSignUp follows ConfirmSignUp and AdminConfirmSignUp.
	// Cognito doesn't send it for users created with AdminCreateUser.
	TriggerConfirmSignUp = "PostConfirmation_ConfirmSignUp"
	// TriggerConfirmForgotPassword follows ConfirmForgotPassword.
	TriggerConfirmForgotPassword = "PostConfirmation_ConfirmForgotPassword"
)

Trigger sources sent to the PostConfirmation trigger.

View Source
const (
	// ActionReplacePassword replaces the user's password with a random one.
	// It is the default when the policy returns no password action, and it
	// wins over ActionSkipPassword.
	ActionReplacePassword = "password.replace"
	// ActionSkipPassword keeps the user's password. It takes an optional
	// "reason", which is logged.
	ActionSkipPassword = "password.skip"
)

Actions a PostConfirmation policy can return.

View Source
const PasswordLength = 128

PasswordLength is the length of the random password set on each user. A user pool's minimum password length can be up to 99, and Cognito accepts passwords of up to 256 characters.

View Source
const PolicyQuery = "data.cognito_hook_postconfirmation.result"

PolicyQuery is the rule the optional PostConfirmation policy must define.

View Source
const RecordTimeout = 500 * time.Millisecond

RecordTimeout bounds recording a replacement in the rotation table.

View Source
const TriggerPrefix = "PostConfirmation_"

TriggerPrefix starts every PostConfirmation trigger source.

View Source
const UserStatusExternalProvider = "EXTERNAL_PROVIDER"

UserStatusExternalProvider is the cognito:user_status of federated users.

Variables

Actions lists the actions a PostConfirmation policy can return.

Functions

This section is empty.

Types

type CognitoAPI

type CognitoAPI interface {
	AdminSetUserPassword(ctx context.Context, params *cip.AdminSetUserPasswordInput, optFns ...func(*cip.Options)) (*cip.AdminSetUserPasswordOutput, error)
}

CognitoAPI is the part of the Cognito API the hook calls.

type Config

type Config struct {
	Cognito CognitoAPI
	// Policy decides the actions for each user. Without one, every native
	// user's password is replaced.
	Policy *policy.Engine
	// Rotations, when set, records each replacement, so the PreAuthentication
	// hook doesn't replace the password again at the user's first sign-in.
	Rotations rotation.Store
}

Config configures the hook.

type Decision

type Decision struct {
	// Actions are the actions the policy returned; empty without a policy.
	Actions []action.Action `json:"actions"`
	// ReplacePassword is false when the password is kept.
	ReplacePassword bool `json:"replacePassword"`
	// Reason is why the password is kept.
	Reason string `json:"reason,omitempty"`
}

Decision is what the hook does for a user, resolved from the policy's actions.

func Decide

func Decide(ctx context.Context, p *policy.Engine, in PolicyInput) (*Decision, error)

Decide evaluates the policy for one input and resolves its actions:

  • password.replace is the default, and wins over password.skip.
  • Unknown actions and parameters make the result invalid.

func DefaultDecision

func DefaultDecision() *Decision

DefaultDecision is the decision without a policy, and when the policy fails: replace the password.

type Event

Event is a PostConfirmation trigger event.

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook handles PostConfirmation events.

func New

func New(cfg Config) (*Hook, error)

New returns the hook.

func (*Hook) Handle

func (h *Hook) Handle(ctx context.Context, e *Event) error

Handle runs the policy and carries out its decision. It never returns an error: Cognito has already confirmed the user, so failing would show the user an error without undoing anything. When the policy fails, the hook replaces the password anyway; a failed replacement is logged as "password replacement failed", and one that can't be recorded as "password replacement not recorded".

type PolicyInput

type PolicyInput struct {
	cognito.Header
	UserAttributes map[string]string `json:"userAttributes"`
	ClientMetadata map[string]string `json:"clientMetadata"`
}

PolicyInput is the policy's input document.

func NewPolicyInput

func NewPolicyInput(e *Event) PolicyInput

NewPolicyInput builds the policy input for an event.

Jump to

Keyboard shortcuts

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