ID tokens
The ID token is a JSON Web Token (JWT) that contains user profile information (like the user's name, email, and so forth), represented in the form of claims. These claims are statements about the user, which can be trusted if the consumer of the token can verify its signature. An ID token is part of the OpenID Connect specification and is issued as a result of a valid authorization request with an OpenID scope.
To get the ID token from the Android SDK, you need to call the UserClient#getIdToken()
method. To obtain a token, there are some prerequisites:
-
The user must be registered with an OpenID scope.
-
The user must be authenticated.
The UserClient#getIdToken()
method returns null if the prerequisites aren't met.
Example code: ID token
private void authenticateDevice() {
private void showIdToken() {
final String idToken = OneginiSDK.getOneginiClient(this).getUserClient().getIdToken();
final String content;
if (idToken != null) {
content = getFormattedUserInfo(idToken);
} else {
content = getString(R.string.id_token_null_description);
}
idTokenTextView.setText(content);
}
private String getFormattedUserInfo(final String idToken) {
final String jwtPayload = idToken.split("\\.")[1];
final String decodedJson =
new String(Base64.decode(jwtPayload, Base64.DEFAULT), StandardCharsets.UTF_8);
return new GsonBuilder()
.setPrettyPrinting()
.create()
.toJson(new JsonParser().parse(decodedJson));
}
}