Amazon Cognito Identity Provider

2024/09/12 - Amazon Cognito Identity Provider - 8 updated api methods

Changes  Added email MFA option to user pools with advanced security features.

AdminInitiateAuth (updated) Link ¶
Changes (response)
{'ChallengeName': {'EMAIL_OTP'}}

Initiates the authentication flow, as an administrator.

Note

This action might generate an SMS text message. Starting June 1, 2021, US telecom carriers require you to register an origination phone number before you can send SMS messages to US phone numbers. If you use SMS text messages in Amazon Cognito, you must register a phone number with Amazon Pinpoint. Amazon Cognito uses the registered number automatically. Otherwise, Amazon Cognito users who must receive SMS messages might not be able to sign up, activate their accounts, or sign in.

If you have never used SMS text messages with Amazon Cognito or any other Amazon Web Servicesservice, Amazon Simple Notification Service might place your account in the SMS sandbox. In sandbox mode , you can send messages only to verified phone numbers. After you test your app while in the sandbox environment, you can move out of the sandbox and into production. For more information, see SMS message settings for Amazon Cognito user pools in the Amazon Cognito Developer Guide .

Note

Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.

Learn more

See also: AWS API Documentation

Request Syntax

client.admin_initiate_auth(
    UserPoolId='string',
    ClientId='string',
    AuthFlow='USER_SRP_AUTH'|'REFRESH_TOKEN_AUTH'|'REFRESH_TOKEN'|'CUSTOM_AUTH'|'ADMIN_NO_SRP_AUTH'|'USER_PASSWORD_AUTH'|'ADMIN_USER_PASSWORD_AUTH',
    AuthParameters={
        'string': 'string'
    },
    ClientMetadata={
        'string': 'string'
    },
    AnalyticsMetadata={
        'AnalyticsEndpointId': 'string'
    },
    ContextData={
        'IpAddress': 'string',
        'ServerName': 'string',
        'ServerPath': 'string',
        'HttpHeaders': [
            {
                'headerName': 'string',
                'headerValue': 'string'
            },
        ],
        'EncodedData': 'string'
    }
)
type UserPoolId

string

param UserPoolId

[REQUIRED]

The ID of the Amazon Cognito user pool.

type ClientId

string

param ClientId

[REQUIRED]

The app client ID.

type AuthFlow

string

param AuthFlow

[REQUIRED]

The authentication flow for this call to run. The API action will depend on this value. For example:

  • REFRESH_TOKEN_AUTH will take in a valid refresh token and return new tokens.

  • USER_SRP_AUTH will take in USERNAME and SRP_A and return the Secure Remote Password (SRP) protocol variables to be used for next challenge execution.

  • ADMIN_USER_PASSWORD_AUTH will take in USERNAME and PASSWORD and return the next challenge or tokens.

Valid values include:

  • USER_SRP_AUTH : Authentication flow for the Secure Remote Password (SRP) protocol.

  • REFRESH_TOKEN_AUTH / REFRESH_TOKEN : Authentication flow for refreshing the access token and ID token by supplying a valid refresh token.

  • CUSTOM_AUTH : Custom authentication flow.

  • ADMIN_NO_SRP_AUTH : Non-SRP authentication flow; you can pass in the USERNAME and PASSWORD directly if the flow is enabled for calling the app client.

  • ADMIN_USER_PASSWORD_AUTH : Admin-based user password authentication. This replaces the ADMIN_NO_SRP_AUTH authentication flow. In this flow, Amazon Cognito receives the password in the request instead of using the SRP process to verify passwords.

type AuthParameters

dict

param AuthParameters

The authentication parameters. These are inputs corresponding to the AuthFlow that you're invoking. The required values depend on the value of AuthFlow :

  • For USER_SRP_AUTH : USERNAME (required), SRP_A (required), SECRET_HASH (required if the app client is configured with a client secret), DEVICE_KEY .

  • For ADMIN_USER_PASSWORD_AUTH : USERNAME (required), PASSWORD (required), SECRET_HASH (required if the app client is configured with a client secret), DEVICE_KEY .

  • For REFRESH_TOKEN_AUTH/REFRESH_TOKEN : REFRESH_TOKEN (required), SECRET_HASH (required if the app client is configured with a client secret), DEVICE_KEY .

  • For CUSTOM_AUTH : USERNAME (required), SECRET_HASH (if app client is configured with client secret), DEVICE_KEY . To start the authentication flow with password verification, include ChallengeName: SRP_A and SRP_A: (The SRP_A Value) .

For more information about SECRET_HASH , see Computing secret hash values. For information about DEVICE_KEY , see Working with user devices in your user pool.

  • (string) --

    • (string) --

type ClientMetadata

dict

param ClientMetadata

A map of custom key-value pairs that you can provide as input for certain custom workflows that this action triggers.

You create custom workflows by assigning Lambda functions to user pool triggers. When you use the AdminInitiateAuth API action, Amazon Cognito invokes the Lambda functions that are specified for various triggers. The ClientMetadata value is passed as input to the functions for only the following triggers:

  • Pre signup

  • Pre authentication

  • User migration

When Amazon Cognito invokes the functions for these triggers, it passes a JSON payload, which the function receives as input. This payload contains a validationData attribute, which provides the data that you assigned to the ClientMetadata parameter in your AdminInitiateAuth request. In your function code in Lambda, you can process the validationData value to enhance your workflow for your specific needs.

When you use the AdminInitiateAuth API action, Amazon Cognito also invokes the functions for the following triggers, but it doesn't provide the ClientMetadata value as input:

  • Post authentication

  • Custom message

  • Pre token generation

  • Create auth challenge

  • Define auth challenge

For more information, see Customizing user pool Workflows with Lambda Triggers in the Amazon Cognito Developer Guide .

Note

When you use the ClientMetadata parameter, remember that Amazon Cognito won't do the following:

  • Store the ClientMetadata value. This data is available only to Lambda triggers that are assigned to a user pool to support custom workflows. If your user pool configuration doesn't include triggers, the ClientMetadata parameter serves no purpose.

  • Validate the ClientMetadata value.

  • Encrypt the ClientMetadata value. Don't use Amazon Cognito to provide sensitive information.

  • (string) --

    • (string) --

type AnalyticsMetadata

dict

param AnalyticsMetadata

The analytics metadata for collecting Amazon Pinpoint metrics for AdminInitiateAuth calls.

  • AnalyticsEndpointId (string) --

    The endpoint ID.

type ContextData

dict

param ContextData

Contextual data about your user session, such as the device fingerprint, IP address, or location. Amazon Cognito advanced security evaluates the risk of an authentication event based on the context that your app generates and passes to Amazon Cognito when it makes API requests.

  • IpAddress (string) -- [REQUIRED]

    The source IP address of your user's device.

  • ServerName (string) -- [REQUIRED]

    Your server endpoint where this API is invoked.

  • ServerPath (string) -- [REQUIRED]

    Your server path where this API is invoked.

  • HttpHeaders (list) -- [REQUIRED]

    HttpHeaders received on your server in same order.

    • (dict) --

      The HTTP header.

      • headerName (string) --

        The header name.

      • headerValue (string) --

        The header value.

  • EncodedData (string) --

    Encoded device-fingerprint details that your app collected with the Amazon Cognito context data collection library. For more information, see Adding user device and session data to API requests.

rtype

dict

returns

Response Syntax

{
    'ChallengeName': 'SMS_MFA'|'EMAIL_OTP'|'SOFTWARE_TOKEN_MFA'|'SELECT_MFA_TYPE'|'MFA_SETUP'|'PASSWORD_VERIFIER'|'CUSTOM_CHALLENGE'|'DEVICE_SRP_AUTH'|'DEVICE_PASSWORD_VERIFIER'|'ADMIN_NO_SRP_AUTH'|'NEW_PASSWORD_REQUIRED',
    'Session': 'string',
    'ChallengeParameters': {
        'string': 'string'
    },
    'AuthenticationResult': {
        'AccessToken': 'string',
        'ExpiresIn': 123,
        'TokenType': 'string',
        'RefreshToken': 'string',
        'IdToken': 'string',
        'NewDeviceMetadata': {
            'DeviceKey': 'string',
            'DeviceGroupKey': 'string'
        }
    }
}

Response Structure

  • (dict) --

    Initiates the authentication response, as an administrator.

    • ChallengeName (string) --

      The name of the challenge that you're responding to with this call. This is returned in the AdminInitiateAuth response if you must pass another challenge.

      • MFA_SETUP : If MFA is required, users who don't have at least one of the MFA methods set up are presented with an MFA_SETUP challenge. The user must set up at least one MFA type to continue to authenticate.

      • SELECT_MFA_TYPE : Selects the MFA type. Valid MFA options are SMS_MFA for SMS message MFA, EMAIL_OTP for email message MFA, and SOFTWARE_TOKEN_MFA for time-based one-time password (TOTP) software token MFA.

      • SMS_MFA : Next challenge is to supply an SMS_MFA_CODE that your user pool delivered in an SMS message.

      • EMAIL_OTP : Next challenge is to supply an EMAIL_OTP_CODE that your user pool delivered in an email message.

      • PASSWORD_VERIFIER : Next challenge is to supply PASSWORD_CLAIM_SIGNATURE , PASSWORD_CLAIM_SECRET_BLOCK , and TIMESTAMP after the client-side SRP calculations.

      • CUSTOM_CHALLENGE : This is returned if your custom authentication flow determines that the user should pass another challenge before tokens are issued.

      • DEVICE_SRP_AUTH : If device tracking was activated in your user pool and the previous challenges were passed, this challenge is returned so that Amazon Cognito can start tracking this device.

      • DEVICE_PASSWORD_VERIFIER : Similar to PASSWORD_VERIFIER , but for devices only.

      • ADMIN_NO_SRP_AUTH : This is returned if you must authenticate with USERNAME and PASSWORD directly. An app client must be enabled to use this flow.

      • NEW_PASSWORD_REQUIRED : For users who are required to change their passwords after successful first login. Respond to this challenge with NEW_PASSWORD and any required attributes that Amazon Cognito returned in the requiredAttributes parameter. You can also set values for attributes that aren't required by your user pool and that your app client can write. For more information, see AdminRespondToAuthChallenge.

      Note

      In a NEW_PASSWORD_REQUIRED challenge response, you can't modify a required attribute that already has a value. In AdminRespondToAuthChallenge , set a value for any keys that Amazon Cognito returned in the requiredAttributes parameter, then use the AdminUpdateUserAttributes API operation to modify the value of any additional attributes.

      • MFA_SETUP : For users who are required to set up an MFA factor before they can sign in. The MFA types activated for the user pool will be listed in the challenge parameters MFAS_CAN_SETUP value. To set up software token MFA, use the session returned here from InitiateAuth as an input to AssociateSoftwareToken , and use the session returned by VerifySoftwareToken as an input to RespondToAuthChallenge with challenge name MFA_SETUP to complete sign-in. To set up SMS MFA, users will need help from an administrator to add a phone number to their account and then call InitiateAuth again to restart sign-in.

    • Session (string) --

      The session that should be passed both ways in challenge-response calls to the service. If AdminInitiateAuth or AdminRespondToAuthChallenge API call determines that the caller must pass another challenge, they return a session with other challenge parameters. This session should be passed as it is to the next AdminRespondToAuthChallenge API call.

    • ChallengeParameters (dict) --

      The challenge parameters. These are returned to you in the AdminInitiateAuth response if you must pass another challenge. The responses in this parameter should be used to compute inputs to the next call ( AdminRespondToAuthChallenge ).

      All challenges require USERNAME and SECRET_HASH (if applicable).

      The value of the USER_ID_FOR_SRP attribute is the user's actual username, not an alias (such as email address or phone number), even if you specified an alias in your call to AdminInitiateAuth . This happens because, in the AdminRespondToAuthChallenge API ChallengeResponses , the USERNAME attribute can't be an alias.

      • (string) --

        • (string) --

    • AuthenticationResult (dict) --

      The result of the authentication response. This is only returned if the caller doesn't need to pass another challenge. If the caller does need to pass another challenge before it gets tokens, ChallengeName , ChallengeParameters , and Session are returned.

      • AccessToken (string) --

        A valid access token that Amazon Cognito issued to the user who you want to authenticate.

      • ExpiresIn (integer) --

        The expiration period of the authentication result in seconds.

      • TokenType (string) --

        The token type.

      • RefreshToken (string) --

        The refresh token.

      • IdToken (string) --

        The ID token.

      • NewDeviceMetadata (dict) --

        The new device metadata from an authentication result.

        • DeviceKey (string) --

          The device key.

        • DeviceGroupKey (string) --

          The device group key.

AdminRespondToAuthChallenge (updated) Link ¶
Changes (both)
{'ChallengeName': {'EMAIL_OTP'}}

Some API operations in a user pool generate a challenge, like a prompt for an MFA code, for device authentication that bypasses MFA, or for a custom authentication challenge. An AdminRespondToAuthChallenge API request provides the answer to that challenge, like a code or a secure remote password (SRP). The parameters of a response to an authentication challenge vary with the type of challenge.

For more information about custom authentication challenges, see Custom authentication challenge Lambda triggers.

Note

This action might generate an SMS text message. Starting June 1, 2021, US telecom carriers require you to register an origination phone number before you can send SMS messages to US phone numbers. If you use SMS text messages in Amazon Cognito, you must register a phone number with Amazon Pinpoint. Amazon Cognito uses the registered number automatically. Otherwise, Amazon Cognito users who must receive SMS messages might not be able to sign up, activate their accounts, or sign in.

If you have never used SMS text messages with Amazon Cognito or any other Amazon Web Servicesservice, Amazon Simple Notification Service might place your account in the SMS sandbox. In sandbox mode , you can send messages only to verified phone numbers. After you test your app while in the sandbox environment, you can move out of the sandbox and into production. For more information, see SMS message settings for Amazon Cognito user pools in the Amazon Cognito Developer Guide .

Note

Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.

Learn more

See also: AWS API Documentation

Request Syntax

client.admin_respond_to_auth_challenge(
    UserPoolId='string',
    ClientId='string',
    ChallengeName='SMS_MFA'|'EMAIL_OTP'|'SOFTWARE_TOKEN_MFA'|'SELECT_MFA_TYPE'|'MFA_SETUP'|'PASSWORD_VERIFIER'|'CUSTOM_CHALLENGE'|'DEVICE_SRP_AUTH'|'DEVICE_PASSWORD_VERIFIER'|'ADMIN_NO_SRP_AUTH'|'NEW_PASSWORD_REQUIRED',
    ChallengeResponses={
        'string': 'string'
    },
    Session='string',
    AnalyticsMetadata={
        'AnalyticsEndpointId': 'string'
    },
    ContextData={
        'IpAddress': 'string',
        'ServerName': 'string',
        'ServerPath': 'string',
        'HttpHeaders': [
            {
                'headerName': 'string',
                'headerValue': 'string'
            },
        ],
        'EncodedData': 'string'
    },
    ClientMetadata={
        'string': 'string'
    }
)
type UserPoolId

string

param UserPoolId

[REQUIRED]

The ID of the Amazon Cognito user pool.

type ClientId

string

param ClientId

[REQUIRED]

The app client ID.

type ChallengeName

string

param ChallengeName

[REQUIRED]

The challenge name. For more information, see AdminInitiateAuth.

type ChallengeResponses

dict

param ChallengeResponses

The responses to the challenge that you received in the previous request. Each challenge has its own required response parameters. The following examples are partial JSON request bodies that highlight challenge-response parameters.

Warning

You must provide a SECRET_HASH parameter in all challenge responses to an app client that has a client secret.

SMS_MFA

"ChallengeName": "SMS_MFA", "ChallengeResponses": {"SMS_MFA_CODE": "[code]", "USERNAME": "[username]"}

EMAIL_OTP

"ChallengeName": "EMAIL_OTP", "ChallengeResponses": {"EMAIL_OTP_CODE": "[code]", "USERNAME": "[username]"}

PASSWORD_VERIFIER

This challenge response is part of the SRP flow. Amazon Cognito requires that your application respond to this challenge within a few seconds. When the response time exceeds this period, your user pool returns a NotAuthorizedException error.

"ChallengeName": "PASSWORD_VERIFIER", "ChallengeResponses": {"PASSWORD_CLAIM_SIGNATURE": "[claim_signature]", "PASSWORD_CLAIM_SECRET_BLOCK": "[secret_block]", "TIMESTAMP": [timestamp], "USERNAME": "[username]"}

Add "DEVICE_KEY" when you sign in with a remembered device.

CUSTOM_CHALLENGE

"ChallengeName": "CUSTOM_CHALLENGE", "ChallengeResponses": {"USERNAME": "[username]", "ANSWER": "[challenge_answer]"}

Add "DEVICE_KEY" when you sign in with a remembered device.

NEW_PASSWORD_REQUIRED

"ChallengeName": "NEW_PASSWORD_REQUIRED", "ChallengeResponses": {"NEW_PASSWORD": "[new_password]", "USERNAME": "[username]"}

To set any required attributes that InitiateAuth returned in an requiredAttributes parameter, add "userAttributes.[attribute_name]": "[attribute_value]" . This parameter can also set values for writable attributes that aren't required by your user pool.

Note

In a NEW_PASSWORD_REQUIRED challenge response, you can't modify a required attribute that already has a value. In RespondToAuthChallenge , set a value for any keys that Amazon Cognito returned in the requiredAttributes parameter, then use the UpdateUserAttributes API operation to modify the value of any additional attributes.

SOFTWARE_TOKEN_MFA

"ChallengeName": "SOFTWARE_TOKEN_MFA", "ChallengeResponses": {"USERNAME": "[username]", "SOFTWARE_TOKEN_MFA_CODE": [authenticator_code]}

DEVICE_SRP_AUTH

"ChallengeName": "DEVICE_SRP_AUTH", "ChallengeResponses": {"USERNAME": "[username]", "DEVICE_KEY": "[device_key]", "SRP_A": "[srp_a]"}

DEVICE_PASSWORD_VERIFIER

"ChallengeName": "DEVICE_PASSWORD_VERIFIER", "ChallengeResponses": {"DEVICE_KEY": "[device_key]", "PASSWORD_CLAIM_SIGNATURE": "[claim_signature]", "PASSWORD_CLAIM_SECRET_BLOCK": "[secret_block]", "TIMESTAMP": [timestamp], "USERNAME": "[username]"}

MFA_SETUP

"ChallengeName": "MFA_SETUP", "ChallengeResponses": {"USERNAME": "[username]"}, "SESSION": "[Session ID from VerifySoftwareToken]"

SELECT_MFA_TYPE

"ChallengeName": "SELECT_MFA_TYPE", "ChallengeResponses": {"USERNAME": "[username]", "ANSWER": "[SMS_MFA or SOFTWARE_TOKEN_MFA]"}

For more information about SECRET_HASH , see Computing secret hash values. For information about DEVICE_KEY , see Working with user devices in your user pool.

  • (string) --

    • (string) --

type Session

string

param Session

The session that should be passed both ways in challenge-response calls to the service. If an InitiateAuth or RespondToAuthChallenge API call determines that the caller must pass another challenge, it returns a session with other challenge parameters. This session should be passed as it is to the next RespondToAuthChallenge API call.

type AnalyticsMetadata

dict

param AnalyticsMetadata

The analytics metadata for collecting Amazon Pinpoint metrics for AdminRespondToAuthChallenge calls.

  • AnalyticsEndpointId (string) --

    The endpoint ID.

type ContextData

dict

param ContextData

Contextual data about your user session, such as the device fingerprint, IP address, or location. Amazon Cognito advanced security evaluates the risk of an authentication event based on the context that your app generates and passes to Amazon Cognito when it makes API requests.

  • IpAddress (string) -- [REQUIRED]

    The source IP address of your user's device.

  • ServerName (string) -- [REQUIRED]

    Your server endpoint where this API is invoked.

  • ServerPath (string) -- [REQUIRED]

    Your server path where this API is invoked.

  • HttpHeaders (list) -- [REQUIRED]

    HttpHeaders received on your server in same order.

    • (dict) --

      The HTTP header.

      • headerName (string) --

        The header name.

      • headerValue (string) --

        The header value.

  • EncodedData (string) --

    Encoded device-fingerprint details that your app collected with the Amazon Cognito context data collection library. For more information, see Adding user device and session data to API requests.

type ClientMetadata

dict

param ClientMetadata

A map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.

You create custom workflows by assigning Lambda functions to user pool triggers. When you use the AdminRespondToAuthChallenge API action, Amazon Cognito invokes any functions that you have assigned to the following triggers:

  • pre sign-up

  • custom message

  • post authentication

  • user migration

  • pre token generation

  • define auth challenge

  • create auth challenge

  • verify auth challenge response

When Amazon Cognito invokes any of these functions, it passes a JSON payload, which the function receives as input. This payload contains a clientMetadata attribute that provides the data that you assigned to the ClientMetadata parameter in your AdminRespondToAuthChallenge request. In your function code in Lambda, you can process the clientMetadata value to enhance your workflow for your specific needs.

For more information, see Customizing user pool Workflows with Lambda Triggers in the Amazon Cognito Developer Guide .

Note

When you use the ClientMetadata parameter, remember that Amazon Cognito won't do the following:

  • Store the ClientMetadata value. This data is available only to Lambda triggers that are assigned to a user pool to support custom workflows. If your user pool configuration doesn't include triggers, the ClientMetadata parameter serves no purpose.

  • Validate the ClientMetadata value.

  • Encrypt the ClientMetadata value. Don't use Amazon Cognito to provide sensitive information.

  • (string) --

    • (string) --

rtype

dict

returns

Response Syntax

{
    'ChallengeName': 'SMS_MFA'|'EMAIL_OTP'|'SOFTWARE_TOKEN_MFA'|'SELECT_MFA_TYPE'|'MFA_SETUP'|'PASSWORD_VERIFIER'|'CUSTOM_CHALLENGE'|'DEVICE_SRP_AUTH'|'DEVICE_PASSWORD_VERIFIER'|'ADMIN_NO_SRP_AUTH'|'NEW_PASSWORD_REQUIRED',
    'Session': 'string',
    'ChallengeParameters': {
        'string': 'string'
    },
    'AuthenticationResult': {
        'AccessToken': 'string',
        'ExpiresIn': 123,
        'TokenType': 'string',
        'RefreshToken': 'string',
        'IdToken': 'string',
        'NewDeviceMetadata': {
            'DeviceKey': 'string',
            'DeviceGroupKey': 'string'
        }
    }
}

Response Structure

  • (dict) --

    Responds to the authentication challenge, as an administrator.

    • ChallengeName (string) --

      The name of the challenge. For more information, see AdminInitiateAuth.

    • Session (string) --

      The session that should be passed both ways in challenge-response calls to the service. If the caller must pass another challenge, they return a session with other challenge parameters. This session should be passed as it is to the next RespondToAuthChallenge API call.

    • ChallengeParameters (dict) --

      The challenge parameters. For more information, see AdminInitiateAuth.

      • (string) --

        • (string) --

    • AuthenticationResult (dict) --

      The result returned by the server in response to the authentication request.

      • AccessToken (string) --

        A valid access token that Amazon Cognito issued to the user who you want to authenticate.

      • ExpiresIn (integer) --

        The expiration period of the authentication result in seconds.

      • TokenType (string) --

        The token type.

      • RefreshToken (string) --

        The refresh token.

      • IdToken (string) --

        The ID token.

      • NewDeviceMetadata (dict) --

        The new device metadata from an authentication result.

        • DeviceKey (string) --

          The device key.

        • DeviceGroupKey (string) --

          The device group key.

AdminSetUserMFAPreference (updated) Link ¶
Changes (request)
{'EmailMfaSettings': {'Enabled': 'boolean', 'PreferredMfa': 'boolean'}}

Sets the user's multi-factor authentication (MFA) preference, including which MFA options are activated, and if any are preferred. Only one factor can be set as preferred. The preferred MFA factor will be used to authenticate a user if multiple factors are activated. If multiple options are activated and no preference is set, a challenge to choose an MFA option will be returned during sign-in.

Note

Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.

Learn more

See also: AWS API Documentation

Request Syntax

client.admin_set_user_mfa_preference(
    SMSMfaSettings={
        'Enabled': True|False,
        'PreferredMfa': True|False
    },
    SoftwareTokenMfaSettings={
        'Enabled': True|False,
        'PreferredMfa': True|False
    },
    EmailMfaSettings={
        'Enabled': True|False,
        'PreferredMfa': True|False
    },
    Username='string',
    UserPoolId='string'
)
type SMSMfaSettings

dict

param SMSMfaSettings

User preferences for SMS message MFA. Activates or deactivates SMS MFA and sets it as the preferred MFA method when multiple methods are available.

  • Enabled (boolean) --

    Specifies whether SMS message MFA is activated. If an MFA type is activated for a user, the user will be prompted for MFA during all sign-in attempts, unless device tracking is turned on and the device has been trusted.

  • PreferredMfa (boolean) --

    Specifies whether SMS is the preferred MFA method.

type SoftwareTokenMfaSettings

dict

param SoftwareTokenMfaSettings

User preferences for time-based one-time password (TOTP) MFA. Activates or deactivates TOTP MFA and sets it as the preferred MFA method when multiple methods are available.

  • Enabled (boolean) --

    Specifies whether software token MFA is activated. If an MFA type is activated for a user, the user will be prompted for MFA during all sign-in attempts, unless device tracking is turned on and the device has been trusted.

  • PreferredMfa (boolean) --

    Specifies whether software token MFA is the preferred MFA method.

type EmailMfaSettings

dict

param EmailMfaSettings

User preferences for email message MFA. Activates or deactivates email MFA and sets it as the preferred MFA method when multiple methods are available. To activate this setting, advanced security features must be active in your user pool.

  • Enabled (boolean) --

    Specifies whether email message MFA is active for a user. When the value of this parameter is Enabled , the user will be prompted for MFA during all sign-in attempts, unless device tracking is turned on and the device has been trusted.

  • PreferredMfa (boolean) --

    Specifies whether email message MFA is the user's preferred method.

type Username

string

param Username

[REQUIRED]

The username of the user that you want to query or modify. The value of this parameter is typically your user's username, but it can be any of their alias attributes. If username isn't an alias attribute in your user pool, this value must be the sub of a local user or the username of a user from a third-party IdP.

type UserPoolId

string

param UserPoolId

[REQUIRED]

The ID of the user pool where you want to set a user's MFA preferences.

rtype

dict

returns

Response Syntax

{}

Response Structure

  • (dict) --

GetUserPoolMfaConfig (updated) Link ¶
Changes (response)
{'EmailMfaConfiguration': {'Message': 'string', 'Subject': 'string'}}

Gets the user pool multi-factor authentication (MFA) configuration.

See also: AWS API Documentation

Request Syntax

client.get_user_pool_mfa_config(
    UserPoolId='string'
)
type UserPoolId

string

param UserPoolId

[REQUIRED]

The user pool ID.

rtype

dict

returns

Response Syntax

{
    'SmsMfaConfiguration': {
        'SmsAuthenticationMessage': 'string',
        'SmsConfiguration': {
            'SnsCallerArn': 'string',
            'ExternalId': 'string',
            'SnsRegion': 'string'
        }
    },
    'SoftwareTokenMfaConfiguration': {
        'Enabled': True|False
    },
    'EmailMfaConfiguration': {
        'Message': 'string',
        'Subject': 'string'
    },
    'MfaConfiguration': 'OFF'|'ON'|'OPTIONAL'
}

Response Structure

  • (dict) --

    • SmsMfaConfiguration (dict) --

      Shows user pool SMS message configuration for MFA. Includes the message template and the SMS message sending configuration for Amazon SNS.

      • SmsAuthenticationMessage (string) --

        The SMS message that your user pool sends to users with an MFA code. The message must contain the {####} placeholder. In the message, Amazon Cognito replaces this placeholder with the code. If you don't provide this parameter, Amazon Cognito sends messages in the default format.

      • SmsConfiguration (dict) --

        The SMS configuration with the settings that your Amazon Cognito user pool must use to send an SMS message from your Amazon Web Services account through Amazon Simple Notification Service. To request Amazon SNS in the Amazon Web Services Region that you want, the Amazon Cognito user pool uses an Identity and Access Management (IAM) role that you provide for your Amazon Web Services account.

        • SnsCallerArn (string) --

          The Amazon Resource Name (ARN) of the Amazon SNS caller. This is the ARN of the IAM role in your Amazon Web Services account that Amazon Cognito will use to send SMS messages. SMS messages are subject to a spending limit.

        • ExternalId (string) --

          The external ID provides additional security for your IAM role. You can use an ExternalId with the IAM role that you use with Amazon SNS to send SMS messages for your user pool. If you provide an ExternalId , your Amazon Cognito user pool includes it in the request to assume your IAM role. You can configure the role trust policy to require that Amazon Cognito, and any principal, provide the ExternalID . If you use the Amazon Cognito Management Console to create a role for SMS multi-factor authentication (MFA), Amazon Cognito creates a role with the required permissions and a trust policy that demonstrates use of the ExternalId .

          For more information about the ExternalId of a role, see How to use an external ID when granting access to your Amazon Web Services resources to a third party

        • SnsRegion (string) --

          The Amazon Web Services Region to use with Amazon SNS integration. You can choose the same Region as your user pool, or a supported Legacy Amazon SNS alternate Region .

          Amazon Cognito resources in the Asia Pacific (Seoul) Amazon Web Services Region must use your Amazon SNS configuration in the Asia Pacific (Tokyo) Region. For more information, see SMS message settings for Amazon Cognito user pools.

    • SoftwareTokenMfaConfiguration (dict) --

      Shows user pool configuration for time-based one-time password (TOTP) MFA. Includes TOTP enabled or disabled state.

      • Enabled (boolean) --

        Specifies whether software token MFA is activated.

    • EmailMfaConfiguration (dict) --

      Shows user pool email message configuration for MFA. Includes the subject and body of the email message template for MFA messages. To activate this setting, advanced security features must be active in your user pool.

      • Message (string) --

        The template for the email message that your user pool sends to users with an MFA code. The message must contain the {####} placeholder. In the message, Amazon Cognito replaces this placeholder with the code. If you don't provide this parameter, Amazon Cognito sends messages in the default format.

      • Subject (string) --

        The subject of the email message that your user pool sends to users with an MFA code.

    • MfaConfiguration (string) --

      The multi-factor authentication (MFA) configuration. Valid values include:

      • OFF MFA won't be used for any users.

      • ON MFA is required for all users to sign in.

      • OPTIONAL MFA will be required only for individual users who have an MFA factor activated.

InitiateAuth (updated) Link ¶
Changes (response)
{'ChallengeName': {'EMAIL_OTP'}}

Initiates sign-in for a user in the Amazon Cognito user directory. You can't sign in a user with a federated IdP with InitiateAuth . For more information, see Adding user pool sign-in through a third party.

Note

Amazon Cognito doesn't evaluate Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you can't use IAM credentials to authorize requests, and you can't grant IAM permissions in policies. For more information about authorization models in Amazon Cognito, see Using the Amazon Cognito user pools API and user pool endpoints.

Note

This action might generate an SMS text message. Starting June 1, 2021, US telecom carriers require you to register an origination phone number before you can send SMS messages to US phone numbers. If you use SMS text messages in Amazon Cognito, you must register a phone number with Amazon Pinpoint. Amazon Cognito uses the registered number automatically. Otherwise, Amazon Cognito users who must receive SMS messages might not be able to sign up, activate their accounts, or sign in.

If you have never used SMS text messages with Amazon Cognito or any other Amazon Web Servicesservice, Amazon Simple Notification Service might place your account in the SMS sandbox. In sandbox mode , you can send messages only to verified phone numbers. After you test your app while in the sandbox environment, you can move out of the sandbox and into production. For more information, see SMS message settings for Amazon Cognito user pools in the Amazon Cognito Developer Guide .

See also: AWS API Documentation

Request Syntax

client.initiate_auth(
    AuthFlow='USER_SRP_AUTH'|'REFRESH_TOKEN_AUTH'|'REFRESH_TOKEN'|'CUSTOM_AUTH'|'ADMIN_NO_SRP_AUTH'|'USER_PASSWORD_AUTH'|'ADMIN_USER_PASSWORD_AUTH',
    AuthParameters={
        'string': 'string'
    },
    ClientMetadata={
        'string': 'string'
    },
    ClientId='string',
    AnalyticsMetadata={
        'AnalyticsEndpointId': 'string'
    },
    UserContextData={
        'IpAddress': 'string',
        'EncodedData': 'string'
    }
)
type AuthFlow

string

param AuthFlow

[REQUIRED]

The authentication flow for this call to run. The API action will depend on this value. For example:

  • REFRESH_TOKEN_AUTH takes in a valid refresh token and returns new tokens.

  • USER_SRP_AUTH takes in USERNAME and SRP_A and returns the SRP variables to be used for next challenge execution.

  • USER_PASSWORD_AUTH takes in USERNAME and PASSWORD and returns the next challenge or tokens.

Valid values include:

  • USER_SRP_AUTH : Authentication flow for the Secure Remote Password (SRP) protocol.

  • REFRESH_TOKEN_AUTH / REFRESH_TOKEN : Authentication flow for refreshing the access token and ID token by supplying a valid refresh token.

  • CUSTOM_AUTH : Custom authentication flow.

  • USER_PASSWORD_AUTH : Non-SRP authentication flow; user name and password are passed directly. If a user migration Lambda trigger is set, this flow will invoke the user migration Lambda if it doesn't find the user name in the user pool.

ADMIN_NO_SRP_AUTH isn't a valid value.

type AuthParameters

dict

param AuthParameters

The authentication parameters. These are inputs corresponding to the AuthFlow that you're invoking. The required values depend on the value of AuthFlow :

  • For USER_SRP_AUTH : USERNAME (required), SRP_A (required), SECRET_HASH (required if the app client is configured with a client secret), DEVICE_KEY .

  • For USER_PASSWORD_AUTH : USERNAME (required), PASSWORD (required), SECRET_HASH (required if the app client is configured with a client secret), DEVICE_KEY .

  • For REFRESH_TOKEN_AUTH/REFRESH_TOKEN : REFRESH_TOKEN (required), SECRET_HASH (required if the app client is configured with a client secret), DEVICE_KEY .

  • For CUSTOM_AUTH : USERNAME (required), SECRET_HASH (if app client is configured with client secret), DEVICE_KEY . To start the authentication flow with password verification, include ChallengeName: SRP_A and SRP_A: (The SRP_A Value) .

For more information about SECRET_HASH , see Computing secret hash values. For information about DEVICE_KEY , see Working with user devices in your user pool.

  • (string) --

    • (string) --

type ClientMetadata

dict

param ClientMetadata

A map of custom key-value pairs that you can provide as input for certain custom workflows that this action triggers.

You create custom workflows by assigning Lambda functions to user pool triggers. When you use the InitiateAuth API action, Amazon Cognito invokes the Lambda functions that are specified for various triggers. The ClientMetadata value is passed as input to the functions for only the following triggers:

  • Pre signup

  • Pre authentication

  • User migration

When Amazon Cognito invokes the functions for these triggers, it passes a JSON payload, which the function receives as input. This payload contains a validationData attribute, which provides the data that you assigned to the ClientMetadata parameter in your InitiateAuth request. In your function code in Lambda, you can process the validationData value to enhance your workflow for your specific needs.

When you use the InitiateAuth API action, Amazon Cognito also invokes the functions for the following triggers, but it doesn't provide the ClientMetadata value as input:

  • Post authentication

  • Custom message

  • Pre token generation

  • Create auth challenge

  • Define auth challenge

For more information, see Customizing user pool Workflows with Lambda Triggers in the Amazon Cognito Developer Guide .

Note

When you use the ClientMetadata parameter, remember that Amazon Cognito won't do the following:

  • Store the ClientMetadata value. This data is available only to Lambda triggers that are assigned to a user pool to support custom workflows. If your user pool configuration doesn't include triggers, the ClientMetadata parameter serves no purpose.

  • Validate the ClientMetadata value.

  • Encrypt the ClientMetadata value. Don't use Amazon Cognito to provide sensitive information.

  • (string) --

    • (string) --

type ClientId

string

param ClientId

[REQUIRED]

The app client ID.

type AnalyticsMetadata

dict

param AnalyticsMetadata

The Amazon Pinpoint analytics metadata that contributes to your metrics for InitiateAuth calls.

  • AnalyticsEndpointId (string) --

    The endpoint ID.

type UserContextData

dict

param UserContextData

Contextual data about your user session, such as the device fingerprint, IP address, or location. Amazon Cognito advanced security evaluates the risk of an authentication event based on the context that your app generates and passes to Amazon Cognito when it makes API requests.

  • IpAddress (string) --

    The source IP address of your user's device.

  • EncodedData (string) --

    Encoded device-fingerprint details that your app collected with the Amazon Cognito context data collection library. For more information, see Adding user device and session data to API requests.

rtype

dict

returns

Response Syntax

{
    'ChallengeName': 'SMS_MFA'|'EMAIL_OTP'|'SOFTWARE_TOKEN_MFA'|'SELECT_MFA_TYPE'|'MFA_SETUP'|'PASSWORD_VERIFIER'|'CUSTOM_CHALLENGE'|'DEVICE_SRP_AUTH'|'DEVICE_PASSWORD_VERIFIER'|'ADMIN_NO_SRP_AUTH'|'NEW_PASSWORD_REQUIRED',
    'Session': 'string',
    'ChallengeParameters': {
        'string': 'string'
    },
    'AuthenticationResult': {
        'AccessToken': 'string',
        'ExpiresIn': 123,
        'TokenType': 'string',
        'RefreshToken': 'string',
        'IdToken': 'string',
        'NewDeviceMetadata': {
            'DeviceKey': 'string',
            'DeviceGroupKey': 'string'
        }
    }
}

Response Structure

  • (dict) --

    Initiates the authentication response.

    • ChallengeName (string) --

      The name of the challenge that you're responding to with this call. This name is returned in the InitiateAuth response if you must pass another challenge.

      Valid values include the following:

      Note

      All of the following challenges require USERNAME and SECRET_HASH (if applicable) in the parameters.

      • SMS_MFA : Next challenge is to supply an SMS_MFA_CODE that your user pool delivered in an SMS message.

      • EMAIL_OTP : Next challenge is to supply an EMAIL_OTP_CODE that your user pool delivered in an email message.

      • PASSWORD_VERIFIER : Next challenge is to supply PASSWORD_CLAIM_SIGNATURE , PASSWORD_CLAIM_SECRET_BLOCK , and TIMESTAMP after the client-side SRP calculations.

      • CUSTOM_CHALLENGE : This is returned if your custom authentication flow determines that the user should pass another challenge before tokens are issued.

      • DEVICE_SRP_AUTH : If device tracking was activated on your user pool and the previous challenges were passed, this challenge is returned so that Amazon Cognito can start tracking this device.

      • DEVICE_PASSWORD_VERIFIER : Similar to PASSWORD_VERIFIER , but for devices only.

      • NEW_PASSWORD_REQUIRED : For users who are required to change their passwords after successful first login. Respond to this challenge with NEW_PASSWORD and any required attributes that Amazon Cognito returned in the requiredAttributes parameter. You can also set values for attributes that aren't required by your user pool and that your app client can write. For more information, see RespondToAuthChallenge.

      Note

      In a NEW_PASSWORD_REQUIRED challenge response, you can't modify a required attribute that already has a value. In RespondToAuthChallenge , set a value for any keys that Amazon Cognito returned in the requiredAttributes parameter, then use the UpdateUserAttributes API operation to modify the value of any additional attributes.

      • MFA_SETUP : For users who are required to setup an MFA factor before they can sign in. The MFA types activated for the user pool will be listed in the challenge parameters MFAS_CAN_SETUP value. To set up software token MFA, use the session returned here from InitiateAuth as an input to AssociateSoftwareToken . Use the session returned by VerifySoftwareToken as an input to RespondToAuthChallenge with challenge name MFA_SETUP to complete sign-in. To set up SMS MFA, an administrator should help the user to add a phone number to their account, and then the user should call InitiateAuth again to restart sign-in.

    • Session (string) --

      The session that should pass both ways in challenge-response calls to the service. If the caller must pass another challenge, they return a session with other challenge parameters. This session should be passed as it is to the next RespondToAuthChallenge API call.

    • ChallengeParameters (dict) --

      The challenge parameters. These are returned in the InitiateAuth response if you must pass another challenge. The responses in this parameter should be used to compute inputs to the next call ( RespondToAuthChallenge ).

      All challenges require USERNAME and SECRET_HASH (if applicable).

      • (string) --

        • (string) --

    • AuthenticationResult (dict) --

      The result of the authentication response. This result is only returned if the caller doesn't need to pass another challenge. If the caller does need to pass another challenge before it gets tokens, ChallengeName , ChallengeParameters , and Session are returned.

      • AccessToken (string) --

        A valid access token that Amazon Cognito issued to the user who you want to authenticate.

      • ExpiresIn (integer) --

        The expiration period of the authentication result in seconds.

      • TokenType (string) --

        The token type.

      • RefreshToken (string) --

        The refresh token.

      • IdToken (string) --

        The ID token.

      • NewDeviceMetadata (dict) --

        The new device metadata from an authentication result.

        • DeviceKey (string) --

          The device key.

        • DeviceGroupKey (string) --

          The device group key.

RespondToAuthChallenge (updated) Link ¶
Changes (both)
{'ChallengeName': {'EMAIL_OTP'}}

Some API operations in a user pool generate a challenge, like a prompt for an MFA code, for device authentication that bypasses MFA, or for a custom authentication challenge. A RespondToAuthChallenge API request provides the answer to that challenge, like a code or a secure remote password (SRP). The parameters of a response to an authentication challenge vary with the type of challenge.

For more information about custom authentication challenges, see Custom authentication challenge Lambda triggers.

Note

Amazon Cognito doesn't evaluate Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you can't use IAM credentials to authorize requests, and you can't grant IAM permissions in policies. For more information about authorization models in Amazon Cognito, see Using the Amazon Cognito user pools API and user pool endpoints.

Note

This action might generate an SMS text message. Starting June 1, 2021, US telecom carriers require you to register an origination phone number before you can send SMS messages to US phone numbers. If you use SMS text messages in Amazon Cognito, you must register a phone number with Amazon Pinpoint. Amazon Cognito uses the registered number automatically. Otherwise, Amazon Cognito users who must receive SMS messages might not be able to sign up, activate their accounts, or sign in.

If you have never used SMS text messages with Amazon Cognito or any other Amazon Web Servicesservice, Amazon Simple Notification Service might place your account in the SMS sandbox. In sandbox mode , you can send messages only to verified phone numbers. After you test your app while in the sandbox environment, you can move out of the sandbox and into production. For more information, see SMS message settings for Amazon Cognito user pools in the Amazon Cognito Developer Guide .

See also: AWS API Documentation

Request Syntax

client.respond_to_auth_challenge(
    ClientId='string',
    ChallengeName='SMS_MFA'|'EMAIL_OTP'|'SOFTWARE_TOKEN_MFA'|'SELECT_MFA_TYPE'|'MFA_SETUP'|'PASSWORD_VERIFIER'|'CUSTOM_CHALLENGE'|'DEVICE_SRP_AUTH'|'DEVICE_PASSWORD_VERIFIER'|'ADMIN_NO_SRP_AUTH'|'NEW_PASSWORD_REQUIRED',
    Session='string',
    ChallengeResponses={
        'string': 'string'
    },
    AnalyticsMetadata={
        'AnalyticsEndpointId': 'string'
    },
    UserContextData={
        'IpAddress': 'string',
        'EncodedData': 'string'
    },
    ClientMetadata={
        'string': 'string'
    }
)
type ClientId

string

param ClientId

[REQUIRED]

The app client ID.

type ChallengeName

string

param ChallengeName

[REQUIRED]

The challenge name. For more information, see InitiateAuth.

ADMIN_NO_SRP_AUTH isn't a valid value.

type Session

string

param Session

The session that should be passed both ways in challenge-response calls to the service. If InitiateAuth or RespondToAuthChallenge API call determines that the caller must pass another challenge, they return a session with other challenge parameters. This session should be passed as it is to the next RespondToAuthChallenge API call.

type ChallengeResponses

dict

param ChallengeResponses

The responses to the challenge that you received in the previous request. Each challenge has its own required response parameters. The following examples are partial JSON request bodies that highlight challenge-response parameters.

Warning

You must provide a SECRET_HASH parameter in all challenge responses to an app client that has a client secret.

SMS_MFA

"ChallengeName": "SMS_MFA", "ChallengeResponses": {"SMS_MFA_CODE": "[code]", "USERNAME": "[username]"}

EMAIL_OTP

"ChallengeName": "EMAIL_OTP", "ChallengeResponses": {"EMAIL_OTP_CODE": "[code]", "USERNAME": "[username]"}

PASSWORD_VERIFIER

This challenge response is part of the SRP flow. Amazon Cognito requires that your application respond to this challenge within a few seconds. When the response time exceeds this period, your user pool returns a NotAuthorizedException error.

"ChallengeName": "PASSWORD_VERIFIER", "ChallengeResponses": {"PASSWORD_CLAIM_SIGNATURE": "[claim_signature]", "PASSWORD_CLAIM_SECRET_BLOCK": "[secret_block]", "TIMESTAMP": [timestamp], "USERNAME": "[username]"}

Add "DEVICE_KEY" when you sign in with a remembered device.

CUSTOM_CHALLENGE

"ChallengeName": "CUSTOM_CHALLENGE", "ChallengeResponses": {"USERNAME": "[username]", "ANSWER": "[challenge_answer]"}

Add "DEVICE_KEY" when you sign in with a remembered device.

NEW_PASSWORD_REQUIRED

"ChallengeName": "NEW_PASSWORD_REQUIRED", "ChallengeResponses": {"NEW_PASSWORD": "[new_password]", "USERNAME": "[username]"}

To set any required attributes that InitiateAuth returned in an requiredAttributes parameter, add "userAttributes.[attribute_name]": "[attribute_value]" . This parameter can also set values for writable attributes that aren't required by your user pool.

Note

In a NEW_PASSWORD_REQUIRED challenge response, you can't modify a required attribute that already has a value. In RespondToAuthChallenge , set a value for any keys that Amazon Cognito returned in the requiredAttributes parameter, then use the UpdateUserAttributes API operation to modify the value of any additional attributes.

SOFTWARE_TOKEN_MFA

"ChallengeName": "SOFTWARE_TOKEN_MFA", "ChallengeResponses": {"USERNAME": "[username]", "SOFTWARE_TOKEN_MFA_CODE": [authenticator_code]}

DEVICE_SRP_AUTH

"ChallengeName": "DEVICE_SRP_AUTH", "ChallengeResponses": {"USERNAME": "[username]", "DEVICE_KEY": "[device_key]", "SRP_A": "[srp_a]"}

DEVICE_PASSWORD_VERIFIER

"ChallengeName": "DEVICE_PASSWORD_VERIFIER", "ChallengeResponses": {"DEVICE_KEY": "[device_key]", "PASSWORD_CLAIM_SIGNATURE": "[claim_signature]", "PASSWORD_CLAIM_SECRET_BLOCK": "[secret_block]", "TIMESTAMP": [timestamp], "USERNAME": "[username]"}

MFA_SETUP

"ChallengeName": "MFA_SETUP", "ChallengeResponses": {"USERNAME": "[username]"}, "SESSION": "[Session ID from VerifySoftwareToken]"

SELECT_MFA_TYPE

"ChallengeName": "SELECT_MFA_TYPE", "ChallengeResponses": {"USERNAME": "[username]", "ANSWER": "[SMS_MFA or SOFTWARE_TOKEN_MFA]"}

For more information about SECRET_HASH , see Computing secret hash values. For information about DEVICE_KEY , see Working with user devices in your user pool.

  • (string) --

    • (string) --

type AnalyticsMetadata

dict

param AnalyticsMetadata

The Amazon Pinpoint analytics metadata that contributes to your metrics for RespondToAuthChallenge calls.

  • AnalyticsEndpointId (string) --

    The endpoint ID.

type UserContextData

dict

param UserContextData

Contextual data about your user session, such as the device fingerprint, IP address, or location. Amazon Cognito advanced security evaluates the risk of an authentication event based on the context that your app generates and passes to Amazon Cognito when it makes API requests.

  • IpAddress (string) --

    The source IP address of your user's device.

  • EncodedData (string) --

    Encoded device-fingerprint details that your app collected with the Amazon Cognito context data collection library. For more information, see Adding user device and session data to API requests.

type ClientMetadata

dict

param ClientMetadata

A map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers.

You create custom workflows by assigning Lambda functions to user pool triggers. When you use the RespondToAuthChallenge API action, Amazon Cognito invokes any functions that are assigned to the following triggers: post authentication , pre token generation , define auth challenge , create auth challenge , and verify auth challenge . When Amazon Cognito invokes any of these functions, it passes a JSON payload, which the function receives as input. This payload contains a clientMetadata attribute, which provides the data that you assigned to the ClientMetadata parameter in your RespondToAuthChallenge request. In your function code in Lambda, you can process the clientMetadata value to enhance your workflow for your specific needs.

For more information, see Customizing user pool Workflows with Lambda Triggers in the Amazon Cognito Developer Guide .

Note

When you use the ClientMetadata parameter, remember that Amazon Cognito won't do the following:

  • Store the ClientMetadata value. This data is available only to Lambda triggers that are assigned to a user pool to support custom workflows. If your user pool configuration doesn't include triggers, the ClientMetadata parameter serves no purpose.

  • Validate the ClientMetadata value.

  • Encrypt the ClientMetadata value. Don't use Amazon Cognito to provide sensitive information.

  • (string) --

    • (string) --

rtype

dict

returns

Response Syntax

{
    'ChallengeName': 'SMS_MFA'|'EMAIL_OTP'|'SOFTWARE_TOKEN_MFA'|'SELECT_MFA_TYPE'|'MFA_SETUP'|'PASSWORD_VERIFIER'|'CUSTOM_CHALLENGE'|'DEVICE_SRP_AUTH'|'DEVICE_PASSWORD_VERIFIER'|'ADMIN_NO_SRP_AUTH'|'NEW_PASSWORD_REQUIRED',
    'Session': 'string',
    'ChallengeParameters': {
        'string': 'string'
    },
    'AuthenticationResult': {
        'AccessToken': 'string',
        'ExpiresIn': 123,
        'TokenType': 'string',
        'RefreshToken': 'string',
        'IdToken': 'string',
        'NewDeviceMetadata': {
            'DeviceKey': 'string',
            'DeviceGroupKey': 'string'
        }
    }
}

Response Structure

  • (dict) --

    The response to respond to the authentication challenge.

    • ChallengeName (string) --

      The challenge name. For more information, see InitiateAuth.

    • Session (string) --

      The session that should be passed both ways in challenge-response calls to the service. If the caller must pass another challenge, they return a session with other challenge parameters. This session should be passed as it is to the next RespondToAuthChallenge API call.

    • ChallengeParameters (dict) --

      The challenge parameters. For more information, see InitiateAuth.

      • (string) --

        • (string) --

    • AuthenticationResult (dict) --

      The result returned by the server in response to the request to respond to the authentication challenge.

      • AccessToken (string) --

        A valid access token that Amazon Cognito issued to the user who you want to authenticate.

      • ExpiresIn (integer) --

        The expiration period of the authentication result in seconds.

      • TokenType (string) --

        The token type.

      • RefreshToken (string) --

        The refresh token.

      • IdToken (string) --

        The ID token.

      • NewDeviceMetadata (dict) --

        The new device metadata from an authentication result.

        • DeviceKey (string) --

          The device key.

        • DeviceGroupKey (string) --

          The device group key.

SetUserMFAPreference (updated) Link ¶
Changes (request)
{'EmailMfaSettings': {'Enabled': 'boolean', 'PreferredMfa': 'boolean'}}

Set the user's multi-factor authentication (MFA) method preference, including which MFA factors are activated and if any are preferred. Only one factor can be set as preferred. The preferred MFA factor will be used to authenticate a user if multiple factors are activated. If multiple options are activated and no preference is set, a challenge to choose an MFA option will be returned during sign-in. If an MFA type is activated for a user, the user will be prompted for MFA during all sign-in attempts unless device tracking is turned on and the device has been trusted. If you want MFA to be applied selectively based on the assessed risk level of sign-in attempts, deactivate MFA for users and turn on Adaptive Authentication for the user pool.

Authorize this action with a signed-in user's access token. It must include the scope aws.cognito.signin.user.admin .

Note

Amazon Cognito doesn't evaluate Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you can't use IAM credentials to authorize requests, and you can't grant IAM permissions in policies. For more information about authorization models in Amazon Cognito, see Using the Amazon Cognito user pools API and user pool endpoints.

See also: AWS API Documentation

Request Syntax

client.set_user_mfa_preference(
    SMSMfaSettings={
        'Enabled': True|False,
        'PreferredMfa': True|False
    },
    SoftwareTokenMfaSettings={
        'Enabled': True|False,
        'PreferredMfa': True|False
    },
    EmailMfaSettings={
        'Enabled': True|False,
        'PreferredMfa': True|False
    },
    AccessToken='string'
)
type SMSMfaSettings

dict

param SMSMfaSettings

User preferences for SMS message MFA. Activates or deactivates SMS MFA and sets it as the preferred MFA method when multiple methods are available.

  • Enabled (boolean) --

    Specifies whether SMS message MFA is activated. If an MFA type is activated for a user, the user will be prompted for MFA during all sign-in attempts, unless device tracking is turned on and the device has been trusted.

  • PreferredMfa (boolean) --

    Specifies whether SMS is the preferred MFA method.

type SoftwareTokenMfaSettings

dict

param SoftwareTokenMfaSettings

User preferences for time-based one-time password (TOTP) MFA. Activates or deactivates TOTP MFA and sets it as the preferred MFA method when multiple methods are available.

  • Enabled (boolean) --

    Specifies whether software token MFA is activated. If an MFA type is activated for a user, the user will be prompted for MFA during all sign-in attempts, unless device tracking is turned on and the device has been trusted.

  • PreferredMfa (boolean) --

    Specifies whether software token MFA is the preferred MFA method.

type EmailMfaSettings

dict

param EmailMfaSettings

User preferences for email message MFA. Activates or deactivates email MFA and sets it as the preferred MFA method when multiple methods are available. To activate this setting, advanced security features must be active in your user pool.

  • Enabled (boolean) --

    Specifies whether email message MFA is active for a user. When the value of this parameter is Enabled , the user will be prompted for MFA during all sign-in attempts, unless device tracking is turned on and the device has been trusted.

  • PreferredMfa (boolean) --

    Specifies whether email message MFA is the user's preferred method.

type AccessToken

string

param AccessToken

[REQUIRED]

A valid access token that Amazon Cognito issued to the user whose MFA preference you want to set.

rtype

dict

returns

Response Syntax

{}

Response Structure

  • (dict) --

SetUserPoolMfaConfig (updated) Link ¶
Changes (both)
{'EmailMfaConfiguration': {'Message': 'string', 'Subject': 'string'}}

Sets the user pool multi-factor authentication (MFA) configuration.

Note

This action might generate an SMS text message. Starting June 1, 2021, US telecom carriers require you to register an origination phone number before you can send SMS messages to US phone numbers. If you use SMS text messages in Amazon Cognito, you must register a phone number with Amazon Pinpoint. Amazon Cognito uses the registered number automatically. Otherwise, Amazon Cognito users who must receive SMS messages might not be able to sign up, activate their accounts, or sign in.

If you have never used SMS text messages with Amazon Cognito or any other Amazon Web Servicesservice, Amazon Simple Notification Service might place your account in the SMS sandbox. In sandbox mode , you can send messages only to verified phone numbers. After you test your app while in the sandbox environment, you can move out of the sandbox and into production. For more information, see SMS message settings for Amazon Cognito user pools in the Amazon Cognito Developer Guide .

See also: AWS API Documentation

Request Syntax

client.set_user_pool_mfa_config(
    UserPoolId='string',
    SmsMfaConfiguration={
        'SmsAuthenticationMessage': 'string',
        'SmsConfiguration': {
            'SnsCallerArn': 'string',
            'ExternalId': 'string',
            'SnsRegion': 'string'
        }
    },
    SoftwareTokenMfaConfiguration={
        'Enabled': True|False
    },
    EmailMfaConfiguration={
        'Message': 'string',
        'Subject': 'string'
    },
    MfaConfiguration='OFF'|'ON'|'OPTIONAL'
)
type UserPoolId

string

param UserPoolId

[REQUIRED]

The user pool ID.

type SmsMfaConfiguration

dict

param SmsMfaConfiguration

Configures user pool SMS messages for MFA. Sets the message template and the SMS message sending configuration for Amazon SNS.

  • SmsAuthenticationMessage (string) --

    The SMS message that your user pool sends to users with an MFA code. The message must contain the {####} placeholder. In the message, Amazon Cognito replaces this placeholder with the code. If you don't provide this parameter, Amazon Cognito sends messages in the default format.

  • SmsConfiguration (dict) --

    The SMS configuration with the settings that your Amazon Cognito user pool must use to send an SMS message from your Amazon Web Services account through Amazon Simple Notification Service. To request Amazon SNS in the Amazon Web Services Region that you want, the Amazon Cognito user pool uses an Identity and Access Management (IAM) role that you provide for your Amazon Web Services account.

    • SnsCallerArn (string) -- [REQUIRED]

      The Amazon Resource Name (ARN) of the Amazon SNS caller. This is the ARN of the IAM role in your Amazon Web Services account that Amazon Cognito will use to send SMS messages. SMS messages are subject to a spending limit.

    • ExternalId (string) --

      The external ID provides additional security for your IAM role. You can use an ExternalId with the IAM role that you use with Amazon SNS to send SMS messages for your user pool. If you provide an ExternalId , your Amazon Cognito user pool includes it in the request to assume your IAM role. You can configure the role trust policy to require that Amazon Cognito, and any principal, provide the ExternalID . If you use the Amazon Cognito Management Console to create a role for SMS multi-factor authentication (MFA), Amazon Cognito creates a role with the required permissions and a trust policy that demonstrates use of the ExternalId .

      For more information about the ExternalId of a role, see How to use an external ID when granting access to your Amazon Web Services resources to a third party

    • SnsRegion (string) --

      The Amazon Web Services Region to use with Amazon SNS integration. You can choose the same Region as your user pool, or a supported Legacy Amazon SNS alternate Region .

      Amazon Cognito resources in the Asia Pacific (Seoul) Amazon Web Services Region must use your Amazon SNS configuration in the Asia Pacific (Tokyo) Region. For more information, see SMS message settings for Amazon Cognito user pools.

type SoftwareTokenMfaConfiguration

dict

param SoftwareTokenMfaConfiguration

Configures a user pool for time-based one-time password (TOTP) MFA. Enables or disables TOTP.

  • Enabled (boolean) --

    Specifies whether software token MFA is activated.

type EmailMfaConfiguration

dict

param EmailMfaConfiguration

Configures user pool email messages for MFA. Sets the subject and body of the email message template for MFA messages. To activate this setting, advanced security features must be active in your user pool.

  • Message (string) --

    The template for the email message that your user pool sends to users with an MFA code. The message must contain the {####} placeholder. In the message, Amazon Cognito replaces this placeholder with the code. If you don't provide this parameter, Amazon Cognito sends messages in the default format.

  • Subject (string) --

    The subject of the email message that your user pool sends to users with an MFA code.

type MfaConfiguration

string

param MfaConfiguration

The MFA configuration. If you set the MfaConfiguration value to ‘ON’, only users who have set up an MFA factor can sign in. To learn more, see Adding Multi-Factor Authentication (MFA) to a user pool. Valid values include:

  • OFF MFA won't be used for any users.

  • ON MFA is required for all users to sign in.

  • OPTIONAL MFA will be required only for individual users who have an MFA factor activated.

rtype

dict

returns

Response Syntax

{
    'SmsMfaConfiguration': {
        'SmsAuthenticationMessage': 'string',
        'SmsConfiguration': {
            'SnsCallerArn': 'string',
            'ExternalId': 'string',
            'SnsRegion': 'string'
        }
    },
    'SoftwareTokenMfaConfiguration': {
        'Enabled': True|False
    },
    'EmailMfaConfiguration': {
        'Message': 'string',
        'Subject': 'string'
    },
    'MfaConfiguration': 'OFF'|'ON'|'OPTIONAL'
}

Response Structure

  • (dict) --

    • SmsMfaConfiguration (dict) --

      Shows user pool SMS message configuration for MFA. Includes the message template and the SMS message sending configuration for Amazon SNS.

      • SmsAuthenticationMessage (string) --

        The SMS message that your user pool sends to users with an MFA code. The message must contain the {####} placeholder. In the message, Amazon Cognito replaces this placeholder with the code. If you don't provide this parameter, Amazon Cognito sends messages in the default format.

      • SmsConfiguration (dict) --

        The SMS configuration with the settings that your Amazon Cognito user pool must use to send an SMS message from your Amazon Web Services account through Amazon Simple Notification Service. To request Amazon SNS in the Amazon Web Services Region that you want, the Amazon Cognito user pool uses an Identity and Access Management (IAM) role that you provide for your Amazon Web Services account.

        • SnsCallerArn (string) --

          The Amazon Resource Name (ARN) of the Amazon SNS caller. This is the ARN of the IAM role in your Amazon Web Services account that Amazon Cognito will use to send SMS messages. SMS messages are subject to a spending limit.

        • ExternalId (string) --

          The external ID provides additional security for your IAM role. You can use an ExternalId with the IAM role that you use with Amazon SNS to send SMS messages for your user pool. If you provide an ExternalId , your Amazon Cognito user pool includes it in the request to assume your IAM role. You can configure the role trust policy to require that Amazon Cognito, and any principal, provide the ExternalID . If you use the Amazon Cognito Management Console to create a role for SMS multi-factor authentication (MFA), Amazon Cognito creates a role with the required permissions and a trust policy that demonstrates use of the ExternalId .

          For more information about the ExternalId of a role, see How to use an external ID when granting access to your Amazon Web Services resources to a third party

        • SnsRegion (string) --

          The Amazon Web Services Region to use with Amazon SNS integration. You can choose the same Region as your user pool, or a supported Legacy Amazon SNS alternate Region .

          Amazon Cognito resources in the Asia Pacific (Seoul) Amazon Web Services Region must use your Amazon SNS configuration in the Asia Pacific (Tokyo) Region. For more information, see SMS message settings for Amazon Cognito user pools.

    • SoftwareTokenMfaConfiguration (dict) --

      Shows user pool configuration for time-based one-time password (TOTP) MFA. Includes TOTP enabled or disabled state.

      • Enabled (boolean) --

        Specifies whether software token MFA is activated.

    • EmailMfaConfiguration (dict) --

      Shows user pool email message configuration for MFA. Includes the subject and body of the email message template for MFA messages. To activate this setting, advanced security features must be active in your user pool.

      • Message (string) --

        The template for the email message that your user pool sends to users with an MFA code. The message must contain the {####} placeholder. In the message, Amazon Cognito replaces this placeholder with the code. If you don't provide this parameter, Amazon Cognito sends messages in the default format.

      • Subject (string) --

        The subject of the email message that your user pool sends to users with an MFA code.

    • MfaConfiguration (string) --

      The MFA configuration. Valid values include:

      • OFF MFA won't be used for any users.

      • ON MFA is required for all users to sign in.

      • OPTIONAL MFA will be required only for individual users who have an MFA factor enabled.