AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above. demonstrates how to retrieve the ClientID from an identity provider.

/* * Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ package com.example.cognito; import; import; import; import; import java.util.HashMap; public class GetId { public static void main(String[] args) { final String USAGE = "\n" + "Usage:\n" + " GetId <app_id> <identity_pool_id>\n\n" + "Where:\n" + " app_id - the application id from login provider.\n\n" + " identity_pool_id - the Region and GUID of your id of your identity pool.\n\n" + "Example:\n" + " GetId amzn1.application-oa2-client.1234567890112-abcdefg us-east-2:1234567890112-abcdefg\n"; if (args.length < 3) { System.out.println(USAGE); System.exit(1); } /* Read the name from command args */ String app_id = args[0]; String identity_pool_id = args[1]; HashMap<String, String> potential_providers = new HashMap<>(); potential_providers.put("facebook", ""); potential_providers.put("google", ""); potential_providers.put("amazon", ""); potential_providers.put("twitter", ""); potential_providers.put("digits", ""); HashMap<String, String> login_provider = new HashMap<>(); login_provider.put(potential_providers.get("amazon"), app_id); String cognito_user_pool = ""; HashMap login = new HashMap<String, String>(); login.put(cognito_user_pool, app_id); CognitoIdentityClient cognitoclient = CognitoIdentityClient.builder().region(Region.US_EAST_1).build(); GetIdResponse response = cognitoclient.getId(GetIdRequest.builder() .identityPoolId(identity_pool_id) .logins(login) .build()); System.out.println("Identity ID " + response.identityId()); } }

Sample Details

Service: cognito

Last tested: 2019-06-29

Author: jschwarzwalder (AWS)

Type: full-example

On this page: