use of com.amazonaws.services.cognitoidentityprovider.model.AttributeType in project aws-sdk-android by aws-amplify.
the class CognitoUser method initiateUserPasswordAuthRequest.
/**
* Creates a authentication request to start authentication with user-password authentication (without SRP) flow.
*
* @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 required to start authentication flow.
* @return {@link InitiateAuthRequest}, request to start the authentication.
*/
private InitiateAuthRequest initiateUserPasswordAuthRequest(final Map<String, String> clientMetadata, AuthenticationDetails authenticationDetails) {
if (StringUtils.isBlank(authenticationDetails.getUserId()) || StringUtils.isBlank(authenticationDetails.getPassword())) {
throw new CognitoNotAuthorizedException("User name and password are required");
}
final InitiateAuthRequest authRequest = new InitiateAuthRequest();
authRequest.setAuthFlow(CognitoServiceConstants.AUTH_TYPE_INIT_USER_PASSWORD);
authRequest.setClientId(clientId);
authRequest.setClientMetadata(clientMetadata);
authRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_USERNAME, authenticationDetails.getUserId());
authRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_PASSWORD, authenticationDetails.getPassword());
authRequest.addAuthParametersEntry(CognitoServiceConstants.AUTH_PARAM_SECRET_HASH, CognitoSecretHash.getSecretHash(userId, clientId, clientSecret));
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());
}
authRequest.setClientMetadata(userValidationData);
}
return authRequest;
}
use of com.amazonaws.services.cognitoidentityprovider.model.AttributeType 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);
}
use of com.amazonaws.services.cognitoidentityprovider.model.AttributeType 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;
}
use of com.amazonaws.services.cognitoidentityprovider.model.AttributeType in project aws-sdk-android by aws-amplify.
the class CognitoUser method initiateCustomAuthRequest.
/**
* Creates a authentication request to start authentication with custom
* authentication.
*
* @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 required to start a custom authentication
* flow.
* @return {@link InitiateAuthRequest}, request to start with the user SRP
* authentication.
*/
private InitiateAuthRequest initiateCustomAuthRequest(final Map<String, String> clientMetadata, final AuthenticationDetails authenticationDetails, final AuthenticationHelper authenticationHelper) {
final InitiateAuthRequest authRequest = new InitiateAuthRequest();
authRequest.setAuthFlow(CognitoServiceConstants.AUTH_TYPE_INIT_CUSTOM_AUTH);
authRequest.setClientId(clientId);
authRequest.setClientMetadata(clientMetadata);
/**
* Compute secret hash based on the client secret and pass into the AuthParameters if
* the secret hash is not passed in.
*/
Map<String, String> authenticationParameters = authenticationDetails.getAuthenticationParameters();
if (clientSecret != null && authenticationParameters.get(CognitoServiceConstants.AUTH_PARAM_SECRET_HASH) == null) {
secretHash = CognitoSecretHash.getSecretHash(authenticationDetails.getUserId(), clientId, clientSecret);
authenticationParameters.put(CognitoServiceConstants.AUTH_PARAM_SECRET_HASH, secretHash);
}
if (CognitoServiceConstants.AUTH_PARAM_SRP_A.equals(authenticationDetails.getCustomChallenge())) {
authenticationParameters.put(CognitoServiceConstants.AUTH_PARAM_SRP_A, authenticationHelper.getA().toString(16));
}
authRequest.setAuthParameters(authenticationDetails.getAuthenticationParameters());
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());
}
authRequest.setClientMetadata(userValidationData);
}
authRequest.setUserContextData(getUserContextData());
return authRequest;
}
use of com.amazonaws.services.cognitoidentityprovider.model.AttributeType in project aws-sdk-android by aws-amplify.
the class CognitoUserAttributes method getAttributesList.
/**
* Returns the user attributes as a {@link AttributeType} list.
*
* @return {@link AttributeType} Cognito user attributes as a list.
*/
protected List<AttributeType> getAttributesList() {
List<AttributeType> attributesList = new ArrayList<AttributeType>();
if (userAttributes != null) {
for (Map.Entry<String, String> detail : userAttributes.entrySet()) {
AttributeType attribute = new AttributeType();
attribute.setName(detail.getKey());
attribute.setValue(detail.getValue());
attributesList.add(attribute);
}
}
return attributesList;
}
Aggregations