use of com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType in project aws-sdk-android by aws-amplify.
the class CognitoUser method userSrpAuthRequest.
/**
* @param challengeParameters returned by service
* @param password maintained locally
* @param challengeName returned by service
* @param session returned by service
* @param authenticationHelper
* @return
*/
private RespondToAuthChallengeRequest userSrpAuthRequest(final Map<String, String> clientMetadata, final Map<String, String> challengeParameters, final String password, final String challengeName, final String session, final AuthenticationHelper authenticationHelper) {
final String userId = challengeParameters.get(CognitoServiceConstants.CHLG_PARAM_USERNAME);
final String userIdForSRP = challengeParameters.get(CognitoServiceConstants.CHLG_PARAM_USER_ID_FOR_SRP);
final String srpBString = challengeParameters.get(CognitoServiceConstants.CHLG_PARAM_SRP_B);
final String saltString = challengeParameters.get(CognitoServiceConstants.CHLG_PARAM_SALT);
final String secretBlockString = challengeParameters.get(CognitoServiceConstants.CHLG_PARAM_SECRET_BLOCK);
this.usernameInternal = userId;
this.deviceKey = CognitoDeviceHelper.getDeviceKey(usernameInternal, pool.getUserPoolId(), context);
secretHash = CognitoSecretHash.getSecretHash(usernameInternal, clientId, clientSecret);
final BigInteger srpB = new BigInteger(srpBString, 16);
if (srpB.mod(AuthenticationHelper.N).equals(BigInteger.ZERO)) {
throw new CognitoInternalErrorException("SRP error, B cannot be zero");
}
final BigInteger salt = new BigInteger(saltString, 16);
final byte[] key = authenticationHelper.getPasswordAuthenticationKey(userIdForSRP, password, srpB, salt);
final Date timestamp = new Date();
byte[] hmac;
String dateString;
try {
final Mac mac = Mac.getInstance("HmacSHA256");
final SecretKeySpec keySpec = new SecretKeySpec(key, "HmacSHA256");
mac.init(keySpec);
mac.update(pool.getUserPoolId().split("_", 2)[1].getBytes(StringUtils.UTF8));
mac.update(userIdForSRP.getBytes(StringUtils.UTF8));
final byte[] secretBlock = Base64.decode(secretBlockString);
mac.update(secretBlock);
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
dateString = simpleDateFormat.format(timestamp);
final byte[] dateBytes = dateString.getBytes(StringUtils.UTF8);
hmac = mac.doFinal(dateBytes);
} catch (final Exception e) {
throw new CognitoInternalErrorException("SRP error", e);
}
final Map<String, String> srpAuthResponses = new HashMap<String, String>();
srpAuthResponses.put(CognitoServiceConstants.CHLG_RESP_PASSWORD_CLAIM_SECRET_BLOCK, secretBlockString);
srpAuthResponses.put(CognitoServiceConstants.CHLG_RESP_PASSWORD_CLAIM_SIGNATURE, new String(Base64.encode(hmac), StringUtils.UTF8));
srpAuthResponses.put(CognitoServiceConstants.CHLG_RESP_TIMESTAMP, dateString);
srpAuthResponses.put(CognitoServiceConstants.CHLG_RESP_USERNAME, usernameInternal);
srpAuthResponses.put(CognitoServiceConstants.CHLG_RESP_DEVICE_KEY, deviceKey);
srpAuthResponses.put(CognitoServiceConstants.CHLG_RESP_SECRET_HASH, secretHash);
final RespondToAuthChallengeRequest authChallengeRequest = new RespondToAuthChallengeRequest();
authChallengeRequest.setChallengeName(challengeName);
authChallengeRequest.setClientId(clientId);
authChallengeRequest.setSession(session);
authChallengeRequest.setChallengeResponses(srpAuthResponses);
authChallengeRequest.setClientMetadata(clientMetadata);
final String pinpointEndpointId = pool.getPinpointEndpointId();
if (pinpointEndpointId != null) {
AnalyticsMetadataType amd = new AnalyticsMetadataType();
amd.setAnalyticsEndpointId(pinpointEndpointId);
authChallengeRequest.setAnalyticsMetadata(amd);
}
authChallengeRequest.setUserContextData(getUserContextData());
return authChallengeRequest;
}
use of com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType in project aws-sdk-android by aws-amplify.
the class CognitoUser method confirmSignUpInternal.
/**
* Internal method to Confirm Registration.
*
* @param confirmationCode REQUIRED: Code to confirm this user.
* @param forcedAliasCreation REQUIRED: If set over-rides parameter
* contentions
* @param clientMetadata A map of custom key-value pairs that is passed to the lambda function for
* custom workflow.
*/
private void confirmSignUpInternal(final String confirmationCode, final boolean forcedAliasCreation, final Map<String, String> clientMetadata) {
final ConfirmSignUpRequest confirmUserRegistrationRequest = new ConfirmSignUpRequest().withClientId(clientId).withSecretHash(secretHash).withUsername(userId).withConfirmationCode(confirmationCode).withForceAliasCreation(forcedAliasCreation).withClientMetadata(clientMetadata).withUserContextData(getUserContextData());
final String pinpointEndpointId = pool.getPinpointEndpointId();
if (pinpointEndpointId != null) {
final AnalyticsMetadataType amd = new AnalyticsMetadataType();
amd.setAnalyticsEndpointId(pinpointEndpointId);
confirmUserRegistrationRequest.setAnalyticsMetadata(amd);
}
cognitoIdentityProviderClient.confirmSignUp(confirmUserRegistrationRequest);
}
use of com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType in project aws-sdk-android by aws-amplify.
the class CognitoUser method initiateRefreshTokenAuthRequest.
/**
* Creates a request to refresh tokens.
*
* @param currSession REQUIRED: Refresh token.
* @return {@link InitiateAuthRequest}, request to refresh tokens.
*/
private InitiateAuthRequest initiateRefreshTokenAuthRequest(CognitoUserSession currSession) {
final InitiateAuthRequest initiateAuthRequest = new InitiateAuthRequest();
initiateAuthRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_REFRESH_TOKEN, currSession.getRefreshToken().getToken());
if (deviceKey == null) {
if (usernameInternal != null) {
deviceKey = CognitoDeviceHelper.getDeviceKey(usernameInternal, pool.getUserPoolId(), context);
} else {
deviceKey = CognitoDeviceHelper.getDeviceKey(currSession.getUsername(), pool.getUserPoolId(), context);
}
}
initiateAuthRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_DEVICE_KEY, deviceKey);
initiateAuthRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_SECRET_HASH, clientSecret);
initiateAuthRequest.setClientId(clientId);
initiateAuthRequest.setAuthFlow(CognitoServiceConstants.AUTH_TYPE_REFRESH_TOKEN);
final String pinpointEndpointId = pool.getPinpointEndpointId();
if (pinpointEndpointId != null) {
AnalyticsMetadataType amd = new AnalyticsMetadataType();
amd.setAnalyticsEndpointId(pinpointEndpointId);
initiateAuthRequest.setAnalyticsMetadata(amd);
}
initiateAuthRequest.setUserContextData(getUserContextData());
return initiateAuthRequest;
}
Aggregations