///<summary>/// Get an MFA token to authenticate the user with the authenticator.///</summary>///<param name="session">The session name.</param>///<returns>The session name.</returns>publicasync Task<string> AssociateSoftwareTokenAsync(string session){var softwareTokenRequest = new AssociateSoftwareTokenRequest
{
Session = session,
};
var tokenResponse = await _cognitoService.AssociateSoftwareTokenAsync(softwareTokenRequest);
var secretCode = tokenResponse.SecretCode;
Console.WriteLine($"Use the following secret code to set up the authenticator: {secretCode}");
return tokenResponse.Session;
}
classCognitoIdentityProviderWrapper:"""Encapsulates Amazon Cognito actions"""def__init__(self, cognito_idp_client, user_pool_id, client_id, client_secret=None):"""
:param cognito_idp_client: A Boto3 Amazon Cognito Identity Provider client.
:param user_pool_id: The ID of an existing Amazon Cognito user pool.
:param client_id: The ID of a client application registered with the user pool.
:param client_secret: The client secret, if the client has a secret.
"""
self.cognito_idp_client = cognito_idp_client
self.user_pool_id = user_pool_id
self.client_id = client_id
self.client_secret = client_secret
defget_mfa_secret(self, session):"""
Gets a token that can be used to associate an MFA application with the user.
:param session: Session information returned from a previous call to initiate
authentication.
:return: An MFA token that can be used to set up an MFA application.
"""try:
response = self.cognito_idp_client.associate_software_token(Session=session)
except ClientError as err:
logger.error(
"Couldn't get MFA secret. Here's why: %s: %s",
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raiseelse:
response.pop("ResponseMetadata", None)
return response
///<summary>/// Get an MFA token to authenticate the user with the authenticator.///</summary>///<param name="session">The session name.</param>///<returns>The session name.</returns>publicasync Task<string> AssociateSoftwareTokenAsync(string session){var softwareTokenRequest = new AssociateSoftwareTokenRequest
{
Session = session,
};
var tokenResponse = await _cognitoService.AssociateSoftwareTokenAsync(softwareTokenRequest);
var secretCode = tokenResponse.SecretCode;
Console.WriteLine($"Use the following secret code to set up the authenticator: {secretCode}");
return tokenResponse.Session;
}