Example usage for com.amazonaws.services.cognitoidentity.model GetOpenIdTokenForDeveloperIdentityRequest setIdentityId

List of usage examples for com.amazonaws.services.cognitoidentity.model GetOpenIdTokenForDeveloperIdentityRequest setIdentityId

Introduction

In this page you can find the example usage for com.amazonaws.services.cognitoidentity.model GetOpenIdTokenForDeveloperIdentityRequest setIdentityId.

Prototype


public void setIdentityId(String identityId) 

Source Link

Document

A unique identifier in the format REGION:GUID.

Usage

From source file:cf.funge.aworldofplants.provider.CognitoCredentialsProvider.java

License:Open Source License

/**
 * Returns a Cognito IdentityID for the end user and a OpenID Token based on the custom developer authenticated
 * identity provider configured in the CognitoConfiguration class. The OpenID token in the UserIdentity object is
 * only used to retrieve credentials for the user with the getUserCredentials method and is very short lived.
 *
 * @param user The user that is logging in or registering
 * @return A populated UserIdentity object.
 * @throws AuthorizationException//ww w  .  ja v a 2  s.  c  o  m
 */
public UserIdentity getUserIdentity(User user) throws AuthorizationException {
    if (user == null || user.getUsername() == null || user.getUsername().trim().equals("")) {
        throw new AuthorizationException("Invalid user");
    }

    GetOpenIdTokenForDeveloperIdentityRequest oidcRequest = new GetOpenIdTokenForDeveloperIdentityRequest();
    oidcRequest.setIdentityPoolId(CognitoConfiguration.IDENTITY_POOL_ID);
    if (user.getCognitoIdentityId() != null && !user.getCognitoIdentityId().trim().equals("")) {
        oidcRequest.setIdentityId(user.getCognitoIdentityId());
    }

    oidcRequest.addLoginsEntry(CognitoConfiguration.CUSTOM_PROVIDER_NAME, user.getUsername());

    GetOpenIdTokenForDeveloperIdentityResult resp = identityClient
            .getOpenIdTokenForDeveloperIdentity(oidcRequest);

    if (resp == null) {
        throw new AuthorizationException("Empty GetOpenIdTokenForDeveloperIdentity response");
    }

    UserIdentity identity = new UserIdentity();
    identity.setIdentityId(resp.getIdentityId());
    identity.setOpenIdToken(resp.getToken());
    return identity;
}