Class CognitoIdentityProvider
Provides functionality for user management and authentication with Amazon Cognito Identity Provider.
Inherited Members
Namespace: Innovt.Cloud.AWS.Cognito
Assembly: Innovt.Cloud.AWS.Cognito.dll
Syntax
public abstract class CognitoIdentityProvider : AwsBaseService, IDisposable, ICognitoIdentityProvider
Constructors
| Edit this page View SourceCognitoIdentityProvider(ILogger, IAwsConfiguration, string, string, string, string, bool)
Declaration
protected CognitoIdentityProvider(ILogger logger, IAwsConfiguration configuration, string clientId, string userPoolId, string domainEndPoint, string region = null, bool allowAutoConfirmUserWithSocialLogin = false)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | |
IAwsConfiguration | configuration | |
string | clientId | |
string | userPoolId | |
string | domainEndPoint | |
string | region | |
bool | allowAutoConfirmUserWithSocialLogin |
Methods
| Edit this page View SourceChangePassword(ChangePasswordRequest, CancellationToken)
Changes the password for a user with the specified access token.
Declaration
public virtual Task ChangePassword(ChangePasswordRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
ChangePasswordRequest | command | A ChangePasswordRequest containing the necessary information to change the password. |
CancellationToken | cancellationToken | A cancellation token for cancelling the operation. |
Returns
Type | Description |
---|---|
Task |
Remarks
This method allows you to change the password for a user by providing an access token and the new proposed password. The previous password is also required for security verification. If successful, the user's password will be updated.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
BusinessException | Thrown when the |
ConfirmForgotPassword(ConfirmForgotPasswordRequest, CancellationToken)
Confirms a user's forgotten password and sets a new password for the user.
Declaration
public Task ConfirmForgotPassword(ConfirmForgotPasswordRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
ConfirmForgotPasswordRequest | command | A ConfirmForgotPasswordRequest containing the necessary information for confirmation. |
CancellationToken | cancellationToken | A cancellation token for cancelling the operation. |
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous confirmation process. |
Remarks
This method is used to confirm a user's forgotten password by providing the user's username, a new password, and a confirmation code received by the user. It sets the new password for the user if the confirmation is successful.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
BusinessException | Thrown when the |
ConfirmSignUp(ConfirmSignUpRequest, CancellationToken)
Confirms the sign-up of a user with the specified confirmation code.
Declaration
public virtual Task ConfirmSignUp(ConfirmSignUpRequest request, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
ConfirmSignUpRequest | request | A ConfirmSignUpRequest containing the necessary information to confirm the sign-up. |
CancellationToken | cancellationToken | A cancellation token for cancelling the operation. |
Returns
Type | Description |
---|---|
Task |
Remarks
This method allows you to confirm the sign-up of a user with the specified confirmation code. The confirmation code is typically sent to the user's email or phone number during the registration process. After successful confirmation, the user becomes active and can log in.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
BusinessException | Thrown when the |
DeleteUser(DeleteUserAccountRequest, CancellationToken)
This method will delete the user using the username and the user pool id. It's important to have the admin delete user permission.
Declaration
public Task<bool> DeleteUser(DeleteUserAccountRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
DeleteUserAccountRequest | command | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<bool> |
Exceptions
Type | Condition |
---|---|
Exception |
DisposeServices()
Disposes of resources when they are no longer needed.
Declaration
protected override void DisposeServices()
Overrides
| Edit this page View SourceForgotPassword(ForgotPasswordRequest, CancellationToken)
Sends a forgot password request for a user.
Declaration
public virtual Task ForgotPassword(ForgotPasswordRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
ForgotPasswordRequest | command | The ForgotPasswordRequest containing user information. |
CancellationToken | cancellationToken | A cancellation token for async tasks. |
Returns
Type | Description |
---|---|
Task |
GetUser<T>(GetUserRequest, CancellationToken)
Retrieves user information based on the specified request and response type.
Declaration
public virtual Task<T> GetUser<T>(GetUserRequest request, CancellationToken cancellationToken = default) where T : IGetUserResponse
Parameters
Type | Name | Description |
---|---|---|
GetUserRequest | request | A GetUserRequest containing the criteria for retrieving user information. |
CancellationToken | cancellationToken | A cancellation token for cancelling the operation. |
Returns
Type | Description |
---|---|
Task<T> | An instance of the specified response type containing user information. |
Type Parameters
Name | Description |
---|---|
T | The type of response implementing IGetUserResponse to return. |
Remarks
This method allows you to retrieve user information based on the specified request, such as the user's username or other custom fields. You can specify the response type as a generic parameter, which should implement the IGetUserResponse interface to provide a structured representation of user data. The method returns an instance of the specified response type populated with user information.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
BusinessException | Thrown when the |
GetUser<T>(string, CancellationToken)
Get user information based on the specified request and response type.
Declaration
public virtual Task<T> GetUser<T>(string accessToken, CancellationToken cancellationToken = default) where T : IGetUserResponse
Parameters
Type | Name | Description |
---|---|---|
string | accessToken | A valid access token. |
CancellationToken | cancellationToken | A cancellationToken token |
Returns
Type | Description |
---|---|
Task<T> | Null or a valid user |
Type Parameters
Name | Description |
---|---|
T | A response of type IGetUserResponse |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | |
Exception |
LinkSocialUser(LinkSocialAccountRequest, CancellationToken)
Link user and social account. This is used to avoid billing issues and other problems.
Declaration
public Task<bool> LinkSocialUser(LinkSocialAccountRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
LinkSocialAccountRequest | command | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<bool> |
Exceptions
Type | Condition |
---|---|
Exception |
RefreshToken(RefreshTokenRequest, CancellationToken)
Refreshes an expired access token using a refresh token, allowing the user to remain authenticated.
Declaration
public virtual Task<RefreshTokenResponse> RefreshToken(RefreshTokenRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
RefreshTokenRequest | command | The request containing the refresh token and context information. |
CancellationToken | cancellationToken | A cancellation token for cancelling the operation. |
Returns
Type | Description |
---|---|
Task<RefreshTokenResponse> | A RefreshTokenResponse containing the refreshed access token and associated details. |
Remarks
This method is used to refresh an expired access token using a refresh token, allowing the user to remain authenticated without the need for re-entering credentials. The method constructs a refresh token authentication request, including user context data, and sends it to the Amazon Cognito Identity Provider service. The response contains the refreshed access token and related information.
Exceptions
Type | Condition |
---|---|
BusinessException | Thrown when the refresh token operation is not authorized. |
Exception | Thrown for other exceptions during the refresh token operation. |
ResendConfirmationCode(ResendConfirmationCodeRequest, CancellationToken)
Resends the confirmation code to a user with the specified username.
Declaration
public virtual Task ResendConfirmationCode(ResendConfirmationCodeRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
ResendConfirmationCodeRequest | command | A ResendConfirmationCodeRequest containing the necessary information to resend the confirmation code. |
CancellationToken | cancellationToken | A cancellation token for cancelling the operation. |
Returns
Type | Description |
---|---|
Task |
Remarks
This method allows you to resend the confirmation code to a user with the specified username. The confirmation code is typically used during the user registration process to verify the user's email or phone number.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
BusinessException | Thrown when the |
RespondToAuthChallenge(RespondToAuthChallengeRequest, CancellationToken)
Responds to an authentication challenge with the appropriate challenge responses.
Declaration
public Task<AuthChallengeResponse> RespondToAuthChallenge(RespondToAuthChallengeRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
RespondToAuthChallengeRequest | command | A RespondToAuthChallengeRequest containing the necessary information for the challenge response. |
CancellationToken | cancellationToken | A cancellation token for cancelling the operation. |
Returns
Type | Description |
---|---|
Task<AuthChallengeResponse> | An AuthChallengeResponse containing the authentication result or metadata. |
Remarks
This method is used to respond to various authentication challenges such as custom challenges, SMS Multi-Factor Authentication (MFA), and new password requirements. It provides the appropriate challenge responses based on the challenge type and returns authentication results or metadata.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
BusinessException | Thrown when the |
CriticalException | Thrown when an unsupported challenge name is encountered. |
SignIn(OtpSignInRequest, CancellationToken)
Signs in a user with the provided request for OTP process authentication.
Declaration
public virtual Task<SignInResponse> SignIn(OtpSignInRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
OtpSignInRequest | command | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<SignInResponse> | A SignInResponse with a valid token or null |
SignIn(SignInRequest, CancellationToken)
Signs in a user with the provided authentication information.
Declaration
public virtual Task<SignInResponse> SignIn(SignInRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
SignInRequest | command | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<SignInResponse> |
SignOut(SignOutRequest, CancellationToken)
Signs out the user associated with the provided access token.
Declaration
public Task SignOut(SignOutRequest request, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
SignOutRequest | request | A SignOutRequest object containing the access token to sign out the user. |
CancellationToken | cancellationToken | A cancellation token for cancelling the operation. |
Returns
Type | Description |
---|---|
Task |
Remarks
This method allows you to sign out the user associated with the provided access token. Signing out a user invalidates the access token, preventing further access to protected resources without reauthentication. Ensure that you provide a valid access token to successfully sign out the user.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
BusinessException | Thrown when the |
SignUp(ISignUpRequest, CancellationToken)
Signs up a new user with the provided registration information.
Declaration
public virtual Task<SignUpResponse> SignUp(ISignUpRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
ISignUpRequest | command | An ISignUpRequest object containing the user's registration information. |
CancellationToken | cancellationToken | A cancellation token for cancelling the operation. |
Returns
Type | Description |
---|---|
Task<SignUpResponse> | A SignUpResponse indicating whether the user was successfully signed up and their UUID (User Sub). |
Remarks
This method allows you to sign up a new user with the provided registration information, including username, password, custom attributes, and other optional properties. After successful sign-up, the user may need to confirm their registration depending on the authentication flow and configuration.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
BusinessException | Thrown when the |
SocialSignIn(SocialSignInRequest, CancellationToken)
Performs social sign-in using an authorization code obtained from an external identity provider.
Declaration
public virtual Task<OAuth2SignInResponse> SocialSignIn(SocialSignInRequest command, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
SocialSignInRequest | command | The request containing the authorization code and context information. |
CancellationToken | cancellationToken | A cancellation token for cancelling the operation. |
Returns
Type | Description |
---|---|
Task<OAuth2SignInResponse> | A OAuth2SignInResponse containing user information and tokens for authentication. |
Remarks
This method is used to perform social sign-in using an authorization code obtained from an external identity provider. It constructs an OAuth2 token request, sends it to the identity provider, and handles the response to authenticate the user. The method also retrieves user information and determines if the user needs to be registered in the system.
Exceptions
Type | Condition |
---|---|
BusinessException | Thrown when there is an error in the OAuth2 response. |
CriticalException | Thrown when the user is not found in the system. |
Exception | Thrown for other exceptions during the social sign-in process. |
UpdateUserAttributes(AdminUpdateUserAttributesRequest, CancellationToken)
This method allow you to update user attributes without sending a token. Internally we are calling Admin Update User Attributes.
Declaration
public Task UpdateUserAttributes(AdminUpdateUserAttributesRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
AdminUpdateUserAttributesRequest | command | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
UpdateUserAttributes(UpdateUserAttributesRequest, CancellationToken)
Updates user attributes.
Declaration
public virtual Task UpdateUserAttributes(UpdateUserAttributesRequest command, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
UpdateUserAttributesRequest | command | The UpdateUserAttributesRequest containing user attributes. |
CancellationToken | cancellationToken | A cancellation token for async tasks. |
Returns
Type | Description |
---|---|
Task |