Java Code Examples for org.keycloak.representations.AccessToken#getEmail()
The following examples show how to use
org.keycloak.representations.AccessToken#getEmail() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdapterUtils.java From keycloak with Apache License 2.0 | 6 votes |
public static String getPrincipalName(KeycloakDeployment deployment, AccessToken token) { String attr = "sub"; if (deployment.getPrincipalAttribute() != null) attr = deployment.getPrincipalAttribute(); String name = null; if ("sub".equals(attr)) { name = token.getSubject(); } else if ("email".equals(attr)) { name = token.getEmail(); } else if ("preferred_username".equals(attr)) { name = token.getPreferredUsername(); } else if ("name".equals(attr)) { name = token.getName(); } else if ("given_name".equals(attr)) { name = token.getGivenName(); } else if ("family_name".equals(attr)) { name = token.getFamilyName(); } else if ("nickname".equals(attr)) { name = token.getNickName(); } if (name == null) name = token.getSubject(); return name; }
Example 2
Source File: UserDetailsArgumentResolver.java From slackspace-angular-spring-keycloak with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private Object createUserDetails(NativeWebRequest webRequest) { KeycloakPrincipal<RefreshableKeycloakSecurityContext> principal = (KeycloakPrincipal<RefreshableKeycloakSecurityContext>) webRequest.getUserPrincipal(); AccessToken token = principal.getKeycloakSecurityContext().getToken(); return new UserDetails(token.getId(), token.getGivenName(), token.getFamilyName(), token.getEmail(), token.getRealmAccess().getRoles()); }