Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Feb 21, 2024

Accessing credentials

Amplify Android v1 is deprecated as of June 1st, 2024. No new features or bug fixes will be added. Dependencies may become outdated and potentially introduce compatibility issues.

Please use the latest version (v2) of Amplify Library for Android to get started. Refer to the upgrade guide for instructions on upgrading your application to the latest version.

Amplify libraries should be used for all new cloud connected applications. If you are currently using the AWS Mobile SDK for Android, you can access the documentation here.

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 by following the example below:

Amplify.Auth.fetchAuthSession(
result -> {
AWSCognitoAuthSession cognitoAuthSession = (AWSCognitoAuthSession) result;
switch(cognitoAuthSession.getIdentityId().getType()) {
case SUCCESS:
Log.i("AuthQuickStart", "IdentityId: " + cognitoAuthSession.getIdentityId().getValue());
break;
case FAILURE:
Log.i("AuthQuickStart", "IdentityId not present because: " + cognitoAuthSession.getIdentityId().getError().toString());
}
},
error -> Log.e("AuthQuickStart", error.toString())
);
Amplify.Auth.fetchAuthSession(
{
val session = it as AWSCognitoAuthSession
when (session.identityId.type) {
AuthSessionResult.Type.SUCCESS ->
Log.i("AuthQuickStart", "IdentityId = ${session.identityId.value}")
AuthSessionResult.Type.FAILURE ->
Log.w("AuthQuickStart", "IdentityId not found", session.identityId.error)
}
},
{ Log.e("AuthQuickStart", "Failed to fetch session", it) }
)
try {
val session = Amplify.Auth.fetchAuthSession() as AWSCognitoAuthSession
val id = session.identityId
if (id.type == AuthSessionResult.Type.SUCCESS) {
Log.i("AuthQuickStart", "IdentityId: ${id.value}")
} else if (id.type == AuthSessionResult.Type.FAILURE) {
Log.i("AuthQuickStart", "IdentityId not present: ${id.error}")
}
} catch (error: AuthException) {
Log.e("AuthQuickStart", "Failed to fetch session", error)
}
RxAmplify.Auth.fetchAuthSession()
.subscribe(
result -> {
AWSCognitoAuthSession cognitoAuthSession = (AWSCognitoAuthSession) result;
switch (cognitoAuthSession.getIdentityId().getType()) {
case SUCCESS:
Log.i("AuthQuickStart", "IdentityId: " + cognitoAuthSession.getIdentityId().getValue());
break;
case FAILURE:
Log.i("AuthQuickStart", "IdentityId not present because: " + cognitoAuthSession.getIdentityId().getError().toString());
}
},
error -> Log.e("AuthQuickStart", error.toString())
);