List of usage examples for com.amazonaws.services.cognitoidentity.model GetOpenIdTokenForDeveloperIdentityResult getToken
public String getToken()
An OpenID token.
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 www . j a 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; }
From source file:grails.plugin.awssdk.cognito.AuthUtilities.java
License:Open Source License
public static String prepareJsonResponseForTokens(GetOpenIdTokenForDeveloperIdentityResult result, String key, String identityPoolId) {//from w ww .ja v a 2 s . c o m StringBuilder responseBody = new StringBuilder(); responseBody.append("{"); responseBody.append("\t\"identityPoolId\": \"").append(identityPoolId).append("\","); responseBody.append("\t\"identityId\": \"").append(result.getIdentityId()).append("\","); responseBody.append("\t\"token\": \"").append(result.getToken()).append("\","); responseBody.append("}"); // Encrypting the response return AESEncryption.wrap(responseBody.toString(), key); }