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 ¶
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.
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.
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.
const PolicyQuery = "data.cognito_hook_postconfirmation.result"
PolicyQuery is the rule the optional PostConfirmation policy must define.
const TriggerPrefix = "PostConfirmation_"
TriggerPrefix starts every PostConfirmation trigger source.
const UserStatusExternalProvider = "EXTERNAL_PROVIDER"
UserStatusExternalProvider is the cognito:user_status of federated users.
Variables ¶
var Actions = []string{ActionReplacePassword, ActionSkipPassword}
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
}
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 ¶
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 ¶
type Event = events.CognitoEventUserPoolsPostConfirmation
Event is a PostConfirmation trigger event.
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook handles PostConfirmation events.
func (*Hook) Handle ¶
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".
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.