in src/main/java/com/googlesource/gerrit/plugins/oauth/DexOAuthService.java [89:131]
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
JsonElement tokenJson = JSON.newGson().fromJson(token.getRaw(), JsonElement.class);
JsonObject tokenObject = tokenJson.getAsJsonObject();
JsonElement id_token = tokenObject.get("id_token");
String jwt;
try {
jwt = parseJwt(id_token.getAsString());
} catch (UnsupportedEncodingException e) {
throw new IOException(
String.format(
"%s support is required to interact with JWTs", StandardCharsets.UTF_8.name()),
e);
}
JsonElement claimJson = JSON.newGson().fromJson(jwt, JsonElement.class);
// Dex does not support basic profile currently (2017-09), extracting info
// from access token claim
JsonObject claimObject = claimJson.getAsJsonObject();
JsonElement emailElement = claimObject.get("email");
JsonElement nameElement = claimObject.get("name");
if (emailElement == null || emailElement.isJsonNull()) {
throw new IOException("Response doesn't contain email field");
}
if (nameElement == null || nameElement.isJsonNull()) {
throw new IOException("Response doesn't contain name field");
}
String email = emailElement.getAsString();
String name = nameElement.getAsString();
String username = email;
if (domain != null && domain.length() > 0) {
username = email.replace("@" + domain, "");
}
return new OAuthUserInfo(
DEX_PROVIDER_PREFIX + email /*externalId*/,
username /*username*/,
email /*email*/,
name /*displayName*/,
null /*claimedIdentity*/);
}