ID token
Introduction
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. You can find more information about ID Tokens here.
To get the ID Token from the SDK you need to call UserClient#getIdToken()
method. There are few prerequisites to be able to obtain a token, otherwise method will return null.
- User has to be reigstered with
openid
scope. - User has to be authenticated.
Example code
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));
}