/*
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
using Amazon.Extensions.CognitoAuthentication;
using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Amazon.AspNetCore.Identity.Cognito
{
///
/// Provides an abstraction for a store which manages Cognito accounts.
/// This includes Cognito specific methods such has handling the auth workflow,
/// Retrieving the user status or changing/reseting the password.
///
/// The type encapsulating a user.
public interface IUserCognitoStore : IDisposable where TUser : class
{
///
/// Checks if the can log in with the specified password .
///
/// The user try to log in with.
/// The password supplied for validation.
/// The that represents the asynchronous operation, containing the AuthFlowResponse object linked to that authentication workflow.
Task StartValidatePasswordAsync(TUser user, string password, CancellationToken cancellationToken);
///
/// Changes the password on the cognito account associated with the .
///
/// The user to change the password for.
/// The current password of the user.
/// The new passord for the user.
/// The that represents the asynchronous operation, containing a boolean set to true if changing the password was successful, false otherwise.
Task ChangePasswordAsync(TUser user, string currentPassword, string newPassword, CancellationToken cancellationToken);
///
/// Resets the 's password to the specified after
/// validating the given password reset .
///
/// The user whose password should be reset.
/// The password reset token to verify.
/// The new password to set if reset token verification succeeds.
///
/// The that represents the asynchronous operation, containing the
/// of the operation.
///
Task ChangePasswordWithTokenAsync(TUser user, string token, string newPassword, CancellationToken cancellationToken);
///
/// Checks if the password needs to be changed for the specified .
///
/// The user to check if the password needs to be changed.
/// The that represents the asynchronous operation, containing a boolean set to true if the password needs to be changed, false otherwise.
Task IsPasswordChangeRequiredAsync(TUser user, CancellationToken cancellationToken);
///
/// Checks if the password needs to be reset for the specified .
///
/// The user to check if the password needs to be reset.
/// The that represents the asynchronous operation, containing a boolean set to true if the password needs to be reset, false otherwise.
Task IsPasswordResetRequiredAsync(TUser user, CancellationToken cancellationToken);
///
/// Resets the 's password and sends the confirmation token to the user
/// via email or sms depending on the user pool policy.
///
/// The user to reset the password for.
/// The that represents the asynchronous operation, containing a boolean set to true if the password was reset, false otherwise.
Task ResetPasswordAsync(TUser user, CancellationToken cancellationToken);
///
/// Registers the specified in Cognito with the given password,
/// as an asynchronous operation.
///
/// The user to create.
/// The password for the user to register with
/// The validation data to be sent to the pre sign-up lambda triggers.
///
/// The that represents the asynchronous operation, containing the
/// of the operation.
///
Task CreateAsync(TUser user, string password, IDictionary validationData, CancellationToken cancellationToken);
///
/// Queries Cognito and returns the users in the pool. Optional filters can be applied on the users to retrieve based on their attributes.
/// Providing an empty attributeFilterName parameter returns all the users in the pool.
///
/// The attribute name to filter your search on. You can only search for the following standard attributes:
/// username (case-sensitive)
/// email
/// phone_number
/// name
/// given_name
/// family_name
/// preferred_username
/// cognito:user_status (called Status in the Console) (case-insensitive)
/// status (called Enabled in the Console) (case-sensitive)
/// sub
/// Custom attributes are not searchable.
/// For more information, see Searching for Users Using the ListUsers API and Examples
/// of Using the ListUsers API in the Amazon Cognito Developer Guide.
/// The type of filter to apply:
/// For an exact match, use =
/// For a prefix ("starts with") match, use ^=
///
/// The filter value for the specified attribute.
///
/// The that represents the asynchronous operation, containing a IEnumerable of CognitoUser.
///
Task> GetUsersAsync(CognitoAttribute attributeFilterName, CognitoAttributeFilterType attributeFilterType, string attributeFilterValue, CancellationToken cancellationToken);
///
/// Registers the specified in Cognito with the given password,
/// as an asynchronous operation. Also submits the validation data to the pre sign-up lambda trigger.
///
/// The user to create.
/// The validation data to be sent to the pre sign-up lambda triggers.
///
/// The that represents the asynchronous operation, containing the
/// of the operation.
///
Task CreateAsync(TUser user, IDictionary validationData, CancellationToken cancellationToken);
///
/// Confirms the specified with the specified
/// they were sent by email or sms,
/// as an asynchronous operation.
/// When a new user is confirmed, the user's attribute through which the
/// confirmation code was sent (email address or phone number) is marked as verified.
/// If this attribute is also set to be used as an alias, then the user can sign in with
/// that attribute (email address or phone number) instead of the username.
///
/// The user to confirm.
/// The confirmation code that was sent by email or sms.
/// If set to true, this resolves potential alias conflicts by marking the attribute email or phone number verified.
/// If set to false and an alias conflict exists, then the user confirmation will fail.
///
/// The that represents the asynchronous operation, containing the
/// of the operation.
///
Task ConfirmSignUpAsync(TUser user, string confirmationCode, bool forcedAliasCreation, CancellationToken cancellationToken);
///
/// Admin confirms the specified , regardless of the confirmation code
/// as an asynchronous operation.
///
/// The user to confirm.
///
/// The that represents the asynchronous operation, containing the
/// of the operation.
///
Task AdminConfirmSignUpAsync(TUser user, CancellationToken cancellationToken);
///
/// Resends the account signup confirmation code for the specified
/// as an asynchronous operation.
///
/// The user to resend the account signup confirmation code for.
///
/// The that represents the asynchronous operation, containing the
/// of the operation.
///
Task ResendSignupConfirmationCodeAsync(TUser user, CancellationToken cancellationToken);
///
/// Generates and sends a verification code for the specified ,
/// and the specified ,
/// as an asynchronous operation.
/// This operation requires a logged in user.
///
/// The user to send the verification code to.
/// The attribute to verify.
///
/// The that represents the asynchronous operation, containing the
/// of the operation.
///
Task GetUserAttributeVerificationCodeAsync(TUser user, string attributeName, CancellationToken cancellationToken);
///
/// Verifies the confirmation for the specified ,
/// and the specified ,
/// as an asynchronous operation.
///
/// The user to verify the code for.
/// The attribute to verify.
/// The verification code to check.
///
/// The that represents the asynchronous operation, containing the
/// of the operation.
///
Task VerifyUserAttributeAsync(TUser user, string attributeName, string code, CancellationToken cancellationToken);
///
/// Checks if the can log in with the specified 2fa code challenge .
///
/// The user try to log in with.
/// The 2fa code to check
/// The ongoing Cognito authentication workflow id.
/// The that represents the asynchronous operation, containing the AuthFlowResponse object linked to that authentication workflow.
Task RespondToTwoFactorChallengeAsync(TUser user, string code, string authWorkflowSessionId, CancellationToken cancellationToken);
}
}