Search in sources :

Example 1 with AnalyticsMetadataType

use of com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType in project aws-sdk-android by aws-amplify.

the class CognitoUser method resendConfirmationCodeInternal.

/**
 * Internal method to request registration code resend.
 * @param clientMetadata A map of custom key-value pairs that is passed to the lambda function for
 *                       custom workflow.
 */
private ResendConfirmationCodeResult resendConfirmationCodeInternal(final Map<String, String> clientMetadata) {
    final ResendConfirmationCodeRequest resendConfirmationCodeRequest = new ResendConfirmationCodeRequest().withUsername(userId).withClientId(clientId).withSecretHash(secretHash).withClientMetadata(clientMetadata);
    final String pinpointEndpointId = pool.getPinpointEndpointId();
    resendConfirmationCodeRequest.setUserContextData(getUserContextData());
    if (pinpointEndpointId != null) {
        AnalyticsMetadataType amd = new AnalyticsMetadataType();
        amd.setAnalyticsEndpointId(pinpointEndpointId);
        resendConfirmationCodeRequest.setAnalyticsMetadata(amd);
    }
    return cognitoIdentityProviderClient.resendConfirmationCode(resendConfirmationCodeRequest);
}
Also used : AnalyticsMetadataType(com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType) ResendConfirmationCodeRequest(com.amazonaws.services.cognitoidentityprovider.model.ResendConfirmationCodeRequest)

Example 2 with AnalyticsMetadataType

use of com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType in project aws-sdk-android by aws-amplify.

the class CognitoUser method forgotPasswordInternal.

/**
 * Internal method to start forgot password process.
 */
private ForgotPasswordResult forgotPasswordInternal(final Map<String, String> clientMetadata) {
    final ForgotPasswordRequest resetPasswordRequest = new ForgotPasswordRequest();
    resetPasswordRequest.setClientId(clientId);
    resetPasswordRequest.setSecretHash(secretHash);
    resetPasswordRequest.setUsername(userId);
    resetPasswordRequest.setUserContextData(getUserContextData());
    resetPasswordRequest.setClientMetadata(clientMetadata);
    final String pinpointEndpointId = pool.getPinpointEndpointId();
    if (pinpointEndpointId != null) {
        AnalyticsMetadataType amd = new AnalyticsMetadataType();
        amd.setAnalyticsEndpointId(pinpointEndpointId);
        resetPasswordRequest.setAnalyticsMetadata(amd);
    }
    return cognitoIdentityProviderClient.forgotPassword(resetPasswordRequest);
}
Also used : ConfirmForgotPasswordRequest(com.amazonaws.services.cognitoidentityprovider.model.ConfirmForgotPasswordRequest) ForgotPasswordRequest(com.amazonaws.services.cognitoidentityprovider.model.ForgotPasswordRequest) AnalyticsMetadataType(com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType)

Example 3 with AnalyticsMetadataType

use of com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType in project aws-sdk-android by aws-amplify.

the class CognitoUser method confirmPasswordInternal.

/**
 * Internal method to set a new password.
 *
 * @param verificationCode REQUIRED: Verification code sent to the user.
 * @param newPassword REQUIRED: New password for the user.
 */
private void confirmPasswordInternal(final String verificationCode, final String newPassword, final Map<String, String> clientMetadata) {
    final ConfirmForgotPasswordRequest confirmResetPasswordRequest = new ConfirmForgotPasswordRequest();
    confirmResetPasswordRequest.setUsername(userId);
    confirmResetPasswordRequest.setClientId(clientId);
    confirmResetPasswordRequest.setSecretHash(secretHash);
    confirmResetPasswordRequest.setConfirmationCode(verificationCode);
    confirmResetPasswordRequest.setPassword(newPassword);
    confirmResetPasswordRequest.setUserContextData(getUserContextData());
    confirmResetPasswordRequest.setClientMetadata(clientMetadata);
    final String pinpointEndpointId = pool.getPinpointEndpointId();
    if (pinpointEndpointId != null) {
        AnalyticsMetadataType amd = new AnalyticsMetadataType();
        amd.setAnalyticsEndpointId(pinpointEndpointId);
        confirmResetPasswordRequest.setAnalyticsMetadata(amd);
    }
    cognitoIdentityProviderClient.confirmForgotPassword(confirmResetPasswordRequest);
}
Also used : AnalyticsMetadataType(com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType) ConfirmForgotPasswordRequest(com.amazonaws.services.cognitoidentityprovider.model.ConfirmForgotPasswordRequest)

Example 4 with AnalyticsMetadataType

use of com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType in project aws-sdk-android by aws-amplify.

the class CognitoUserPool method signUpInternal.

/**
 * Internal method to sign-up a new user in Cognito Identity Provider user pool.
 *
 * @param userId            REQUIRED: The new user userId.
 * @param password          REQUIRED: Password you want to associate to this use.
 * @param userAttributes    REQUIRED: User attributes.
 * @param validationData    REQUIRED: Validation key value pairs, these will be passed to pre
 *                          and post registration lambda functions.
 * @param clientMetadata    Client metadata for lambda function for user registration
 * @return SignUpResult
 */
private SignUpResult signUpInternal(String userId, String password, CognitoUserAttributes userAttributes, Map<String, String> validationData, final Map<String, String> clientMetadata) {
    // Create a list of {@link AttributeType} from {@code userAttributes}
    List<AttributeType> validationDataList = null;
    if (validationData != null) {
        validationDataList = new ArrayList<AttributeType>();
        for (final Map.Entry<String, String> data : validationData.entrySet()) {
            final AttributeType validation = new AttributeType();
            validation.setName(data.getKey());
            validation.setValue(data.getValue());
            validationDataList.add(validation);
        }
    }
    // Generate Client secret hash
    secretHash = CognitoSecretHash.getSecretHash(userId, clientId, clientSecret);
    // Create User registration request
    final SignUpRequest signUpUserRequest = new SignUpRequest().withUsername(userId).withPassword(password).withClientId(clientId).withSecretHash(secretHash).withUserAttributes(userAttributes.getAttributesList()).withValidationData(validationDataList).withClientMetadata(clientMetadata).withUserContextData(getUserContextData(userId));
    String ppEndpoint = getPinpointEndpointId();
    if (ppEndpoint != null) {
        AnalyticsMetadataType amd = new AnalyticsMetadataType();
        amd.setAnalyticsEndpointId(ppEndpoint);
        signUpUserRequest.setAnalyticsMetadata(amd);
    }
    return client.signUp(signUpUserRequest);
}
Also used : AnalyticsMetadataType(com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType) AttributeType(com.amazonaws.services.cognitoidentityprovider.model.AttributeType) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) Map(java.util.Map)

Example 5 with AnalyticsMetadataType

use of com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType in project aws-sdk-android by aws-amplify.

the class CognitoUser method initiateUserSrpAuthRequest.

/**
 * Creates a authentication request to start authentication with user SRP
 * verification.
 *
 * @param clientMetadata A map of custom key-value pairs that is passed to the lambda function for
 *                       custom workflow.
 * @param authenticationDetails REQUIRED: {@link AuthenticationDetails},
 *            contains details for user SRP authentication.
 * @param authenticationHelper REQUIRED: Internal helper class for SRP
 *            calculations.
 * @return {@link InitiateAuthRequest}, request to start with the user SRP
 *         authentication.
 */
private InitiateAuthRequest initiateUserSrpAuthRequest(final Map<String, String> clientMetadata, AuthenticationDetails authenticationDetails, AuthenticationHelper authenticationHelper) {
    userId = authenticationDetails.getUserId();
    final InitiateAuthRequest initiateAuthRequest = new InitiateAuthRequest();
    initiateAuthRequest.setAuthFlow(CognitoServiceConstants.AUTH_TYPE_INIT_USER_SRP);
    initiateAuthRequest.setClientId(clientId);
    initiateAuthRequest.setClientMetadata(clientMetadata);
    initiateAuthRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_SECRET_HASH, CognitoSecretHash.getSecretHash(userId, clientId, clientSecret));
    initiateAuthRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_USERNAME, authenticationDetails.getUserId());
    initiateAuthRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_SRP_A, authenticationHelper.getA().toString(SRP_RADIX));
    if (deviceKey == null) {
        initiateAuthRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_DEVICE_KEY, CognitoDeviceHelper.getDeviceKey(authenticationDetails.getUserId(), pool.getUserPoolId(), context));
    } else {
        initiateAuthRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_DEVICE_KEY, deviceKey);
    }
    if (authenticationDetails.getValidationData() != null && authenticationDetails.getValidationData().size() > 0) {
        final Map<String, String> userValidationData = new HashMap<String, String>();
        for (final AttributeType attribute : authenticationDetails.getValidationData()) {
            userValidationData.put(attribute.getName(), attribute.getValue());
        }
        initiateAuthRequest.setClientMetadata(userValidationData);
    }
    final String pinpointEndpointId = this.pool.getPinpointEndpointId();
    if (pinpointEndpointId != null) {
        AnalyticsMetadataType amd = new AnalyticsMetadataType();
        amd.setAnalyticsEndpointId(pinpointEndpointId);
        initiateAuthRequest.setAnalyticsMetadata(amd);
    }
    initiateAuthRequest.setUserContextData(getUserContextData());
    return initiateAuthRequest;
}
Also used : AnalyticsMetadataType(com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType) InitiateAuthRequest(com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthRequest) HashMap(java.util.HashMap) AttributeType(com.amazonaws.services.cognitoidentityprovider.model.AttributeType)

Aggregations

AnalyticsMetadataType (com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType)8 AttributeType (com.amazonaws.services.cognitoidentityprovider.model.AttributeType)2 ConfirmForgotPasswordRequest (com.amazonaws.services.cognitoidentityprovider.model.ConfirmForgotPasswordRequest)2 InitiateAuthRequest (com.amazonaws.services.cognitoidentityprovider.model.InitiateAuthRequest)2 HashMap (java.util.HashMap)2 CognitoInternalErrorException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException)1 CognitoNotAuthorizedException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)1 CognitoParameterInvalidException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException)1 ConfirmSignUpRequest (com.amazonaws.services.cognitoidentityprovider.model.ConfirmSignUpRequest)1 ForgotPasswordRequest (com.amazonaws.services.cognitoidentityprovider.model.ForgotPasswordRequest)1 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)1 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)1 ResendConfirmationCodeRequest (com.amazonaws.services.cognitoidentityprovider.model.ResendConfirmationCodeRequest)1 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)1 RespondToAuthChallengeRequest (com.amazonaws.services.cognitoidentityprovider.model.RespondToAuthChallengeRequest)1 SignUpRequest (com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest)1 UserNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException)1 BigInteger (java.math.BigInteger)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SimpleDateFormat (java.text.SimpleDateFormat)1