Page updated Nov 3, 2023

Accessing credentials

An intentional decision with Amplify Auth was to avoid any public methods exposing credentials or manipulating them.

With Auth, you simply sign in and it handles everything else needed to keep the credentials up to date and vend them to the other categories.

However, if you need to access them in relation to working with an API outside Amplify or want access to AWS specific identifying information (e.g. IdentityId), you can access these implementation details by casting the result of fetchAuthSession as follows:

Amplify.Auth.fetchAuthSession( result -> { AWSCognitoAuthSession cognitoAuthSession = (AWSCognitoAuthSession) result; switch(cognitoAuthSession.getIdentityIdResult().getType()) { case SUCCESS: Log.i("AuthQuickStart", "IdentityId: " + cognitoAuthSession.getIdentityIdResult().getValue()); break; case FAILURE: Log.i("AuthQuickStart", "IdentityId not present because: " + cognitoAuthSession.getIdentityIdResult().getError().toString()); } }, error -> Log.e("AuthQuickStart", error.toString()) );
2 result -> {
3 AWSCognitoAuthSession cognitoAuthSession = (AWSCognitoAuthSession) result;
4 switch(cognitoAuthSession.getIdentityIdResult().getType()) {
5 case SUCCESS:
6 Log.i("AuthQuickStart", "IdentityId: " + cognitoAuthSession.getIdentityIdResult().getValue());
7 break;
8 case FAILURE:
9 Log.i("AuthQuickStart", "IdentityId not present because: " + cognitoAuthSession.getIdentityIdResult().getError().toString());
10 }
11 },
12 error -> Log.e("AuthQuickStart", error.toString())

Force refreshing session

You can ask the plugin to force refresh the internal session by setting the forceRefresh option when calling the fetchAuthSession API.

AuthFetchSessionOptions options = AuthFetchSessionOptions.builder().forceRefresh(true).build();
1AuthFetchSessionOptions options = AuthFetchSessionOptions.builder().forceRefresh(true).build();