Begins setup of time-based one-time password (TOTP) multi-factor authentication (MFA) for a user, with a unique private key that Amazon Cognito generates and returns in the API response. You can authorize an AssociateSoftwareToken request with either the user's access token, or a session string from a challenge response that you received from Amazon Cognito.
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.
Authorize this action with a signed-in user's access token. It must include the scope aws.cognito.signin.user.admin.
Parameters:
-
access_token
(Optional[TokenModelType], default:
None
)
–
A valid access token that Amazon Cognito issued to the currently signed-in user. Must include a scope claim for aws.cognito.signin.user.admin.
You can provide either an access token or a session ID in the request.
-
session
(Optional[SessionType], default:
None
)
–
The session identifier that maintains the state of authentication requests and challenge responses. In AssociateSoftwareToken, this is the session ID from a successful sign-in. You can provide either an access token or a session ID in the request.
Raises:
-
ConcurrentModificationException
–
This exception is thrown if two or more modifications are happening concurrently.
-
ForbiddenException
–
This exception is thrown when WAF doesn't allow your request based on a web ACL that's associated with your user pool.
-
InternalErrorException
–
This exception is thrown when Amazon Cognito encounters an internal error.
-
InvalidParameterException
–
This exception is thrown when the Amazon Cognito service encounters an invalid parameter.
-
NotAuthorizedException
–
This exception is thrown when a user isn't authorized.
-
OperationNotEnabledException
–
This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.
-
ResourceNotFoundException
–
This exception is thrown when the Amazon Cognito service can't find the requested resource.
-
SoftwareTokenMFANotFoundException
–
This exception is thrown when the software token time-based one-time password (TOTP) multi-factor authentication (MFA) isn't activated for the user pool.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Source code in docs_src/capo_cognito_identity_provider/_services/cognito_identity_provider.py
| def associate_software_token(
self,
*,
config_overrides: Optional[CognitoIdentityProviderClientConfig] = None,
access_token: Optional[
"capo_cognito_identity_provider.types.token_model_type.TokenModelType"
] = None,
session: Optional[
"capo_cognito_identity_provider.types.session_type.SessionType"
] = None,
) -> "capo_cognito_identity_provider.types.associate_software_token_response.AssociateSoftwareTokenResponse":
"""<p>Begins setup of time-based one-time password (TOTP) multi-factor authentication (MFA) for a user, with a unique private key that Amazon Cognito generates and returns in the API response. You can authorize an <code>AssociateSoftwareToken</code> request with either the user's access token, or a session string from a challenge response that you received from Amazon Cognito.</p> <note> <p>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 <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pools-API-operations.html">Using the Amazon Cognito user pools API and user pool endpoints</a>.</p> </note> <p>Authorize this action with a signed-in user's access token. It must include the scope <code>aws.cognito.signin.user.admin</code>.</p>
Args:
access_token: <p>A valid access token that Amazon Cognito issued to the currently signed-in user. Must include a scope claim for <code>aws.cognito.signin.user.admin</code>.</p> <p>You can provide either an access token or a session ID in the request.</p>
session: <p>The session identifier that maintains the state of authentication requests and challenge responses. In <code>AssociateSoftwareToken</code>, this is the session ID from a successful sign-in. You can provide either an access token or a session ID in the request.</p>
Raises:
capo_cognito_identity_provider.errors.concurrent_modification_exception.ConcurrentModificationException: <p>This exception is thrown if two or more modifications are happening concurrently.</p>
capo_cognito_identity_provider.errors.forbidden_exception.ForbiddenException: <p>This exception is thrown when WAF doesn't allow your request based on a web ACL that's associated with your user pool.</p>
capo_cognito_identity_provider.errors.internal_error_exception.InternalErrorException: <p>This exception is thrown when Amazon Cognito encounters an internal error.</p>
capo_cognito_identity_provider.errors.invalid_parameter_exception.InvalidParameterException: <p>This exception is thrown when the Amazon Cognito service encounters an invalid parameter.</p>
capo_cognito_identity_provider.errors.not_authorized_exception.NotAuthorizedException: <p>This exception is thrown when a user isn't authorized.</p>
capo_cognito_identity_provider.errors.operation_not_enabled_exception.OperationNotEnabledException: <p>This exception is thrown when an operation is not available in the current region or for the current user pool configuration. This can occur when attempting to perform operations that are not supported in secondary replica regions.</p>
capo_cognito_identity_provider.errors.resource_not_found_exception.ResourceNotFoundException: <p>This exception is thrown when the Amazon Cognito service can't find the requested resource.</p>
capo_cognito_identity_provider.errors.software_token_mfa_not_found_exception.SoftwareTokenMFANotFoundException: <p>This exception is thrown when the software token time-based one-time password (TOTP) multi-factor authentication (MFA) isn't activated for the user pool.</p>
capo_cognito_identity_provider.errors.UnknownServiceError: The service returned an error code this client does not model.
"""
def _handler(
req: "OperationRequest[capo_cognito_identity_provider.types.associate_software_token_request.AssociateSoftwareTokenRequest]",
) -> OperationResponse[
"capo_cognito_identity_provider.types.associate_software_token_response.AssociateSoftwareTokenResponse"
]:
import capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.associate_software_token
output, http_response = (
capo_cognito_identity_provider._operations.aws_cognito_identity_provider_service.associate_software_token.associate_software_token(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
def _redact_input(
input_: "capo_cognito_identity_provider.types.associate_software_token_request.AssociateSoftwareTokenRequest",
) -> dict[str, Any]:
import capo_cognito_identity_provider.types.associate_software_token_request
return capo_cognito_identity_provider.types.associate_software_token_request.redact_sensitive(
input_
)
def _redact_output(
output: "capo_cognito_identity_provider.types.associate_software_token_response.AssociateSoftwareTokenResponse",
) -> dict[str, Any]:
import capo_cognito_identity_provider.types.associate_software_token_response
return capo_cognito_identity_provider.types.associate_software_token_response.redact_sensitive(
output
)
interceptors_, options_ = self.operation_options(
config_overrides,
OperationLogging(
"AssociateSoftwareToken",
redact_input=_redact_input,
redact_output=_redact_output,
),
)
input_: capo_cognito_identity_provider.types.associate_software_token_request.AssociateSoftwareTokenRequest = {}
if access_token is not None:
input_["access_token"] = access_token
if session is not None:
input_["session"] = session
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
response.response.close()
return response.output
|