///<summary>/// Confirm that the user has signed up.///</summary>///<param name="clientId">The Id of this application.</param>///<param name="code">The confirmation code sent to the user.</param>///<param name="userName">The username.</param>///<returns>True if successful.</returns>publicasync Task<bool> ConfirmSignupAsync(string clientId, string code, string userName){var signUpRequest = new ConfirmSignUpRequest
{
ClientId = clientId,
ConfirmationCode = code,
Username = userName,
};
var response = await _cognitoService.ConfirmSignUpAsync(signUpRequest);
if (response.HttpStatusCode == HttpStatusCode.OK)
{
Console.WriteLine($"{userName} was confirmed");
returntrue;
}
returnfalse;
}
有关 API 的详细信息,请参阅 AWS SDK for .NET API 参考ConfirmSignUp中的。
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
defconfirm_user_sign_up(self, user_name, confirmation_code):"""
Confirms a previously created user. A user must be confirmed before they
can sign in to Amazon Cognito.
:param user_name: The name of the user to confirm.
:param confirmation_code: The confirmation code sent to the user's registered
email address.
:return: True when the confirmation succeeds.
"""try:
kwargs = {"ClientId": self.client_id,
"Username": user_name,
"ConfirmationCode": confirmation_code,
}
if self.client_secret isnotNone:
kwargs["SecretHash"] = self._secret_hash(user_name)
self.cognito_idp_client.confirm_sign_up(**kwargs)
except ClientError as err:
logger.error(
"Couldn't confirm sign up for %s. Here's why: %s: %s",
user_name,
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raiseelse:
returnTrue
有关 API 的详细信息,请参阅适用ConfirmSignUp于 Python 的AWS SDK (Boto3) API 参考。
///<summary>/// Confirm that the user has signed up.///</summary>///<param name="clientId">The Id of this application.</param>///<param name="code">The confirmation code sent to the user.</param>///<param name="userName">The username.</param>///<returns>True if successful.</returns>publicasync Task<bool> ConfirmSignupAsync(string clientId, string code, string userName){var signUpRequest = new ConfirmSignUpRequest
{
ClientId = clientId,
ConfirmationCode = code,
Username = userName,
};
var response = await _cognitoService.ConfirmSignUpAsync(signUpRequest);
if (response.HttpStatusCode == HttpStatusCode.OK)
{
Console.WriteLine($"{userName} was confirmed");
returntrue;
}
returnfalse;
}
有关 API 的详细信息,请参阅 AWS SDK for .NET API 参考ConfirmSignUp中的。