0

Hi I am android application developer , I am using cognito authentication mechanism for mobile app. Once i authenticate my user i get RefreshToken and IDToken. According to Amazon cognito it expire IDToken after exactly one hour.I am trying to get my session again to get token again and here is how i am trying to get it done.

    String poolId       = 'xxxxxx';
    String clientId     = 'xxxxxx';
    String clientSecret = 'xxxxxx';

    CognitoUserPool userPool = new CognitoUserPool(context, poolId, clientId, clientSecret,Regions.EU_WEST_1);
    CognitoUser user = userPool.getUser();

    user.getSessionInBackground(new AuthenticationHandler() {

        @Override
        public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {
            String idToken = userSession.getIdToken().getJWTToken();

            Map<String, String> logins = new HashMap<String, String>();
            logins.put("cognito-idp." + Constants.REGION + ".amazonaws.com/" + Constants.UserPool, userSession.getIdToken().getJWTToken());

            credentialsProvider.setLogins(logins);
            credentialsProvider.refresh();
        }

        @Override
        public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) {
            Log.i("MQTT","Detail");
        }

        @Override
        public void getMFACode(MultiFactorAuthenticationContinuation continuation) {
            Log.i("MQTT","MFACode");
        }

        @Override
        public void authenticationChallenge(ChallengeContinuation continuation) {
            Log.i("MQTT","Challenge");
        }

        @Override
        public void onFailure(Exception exception) {
            Log.i("MQTT","Fail");
        }
    });

I have userpoolid and need to know where from i can get clientID and clientSecret.So that i get data in onSuccess callback and get IDToken.

Really thankful if someone can help out. Thanks

Ali Akram
  • 4,803
  • 3
  • 29
  • 38

1 Answers1

0
  • Go to your user pool in cognito and click on the pool you want to work on.

  • Under general settings, click on app clients.

  • Now click on add app client.

  • Give your app a name

  • Make sure the Generate client secret is selected.

  • Click on create client app.

Now you can note down the client id and client secret.

Docs: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-client-apps.html

Ninad Gaikwad
  • 4,272
  • 2
  • 13
  • 23