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

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

Introduction

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

Prototype


public void setIdentityPoolId(String identityPoolId) 

Source Link

Document

An identity pool ID 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/*from w  w w . ja v  a 2 s  .  co  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;
}