fix(oidc): add name claim extraction (#3384)

This commit is contained in:
John Joyce 2021-10-13 18:56:20 -07:00 committed by GitHub
parent 037c89763e
commit a25434c81e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -185,6 +185,10 @@ public class OidcCallbackLogic extends DefaultCallbackLogic<Result, PlayWebConte
String email = profile.getEmail();
URI picture = profile.getPictureUrl();
String displayName = profile.getDisplayName();
String fullName = (String) profile.getAttribute("name"); // Name claim is sometimes provided, including by Google.
if (fullName == null && firstName != null && lastName != null) {
fullName = String.format("%s %s", firstName, lastName);
}
// TODO: Support custom claims mapping. (e.g. department, title, etc)
@ -192,7 +196,7 @@ public class OidcCallbackLogic extends DefaultCallbackLogic<Result, PlayWebConte
userInfo.setActive(true);
userInfo.setFirstName(firstName, SetMode.IGNORE_NULL);
userInfo.setLastName(lastName, SetMode.IGNORE_NULL);
userInfo.setFullName(String.format("%s %s", firstName, lastName), SetMode.IGNORE_NULL);
userInfo.setFullName(fullName, SetMode.IGNORE_NULL);
userInfo.setEmail(email, SetMode.IGNORE_NULL);
// If there is a display name, use it. Otherwise fall back to full name.
userInfo.setDisplayName(displayName == null ? userInfo.getFullName() : displayName, SetMode.IGNORE_NULL);