-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetuserprofile java
26 lines (20 loc) · 954 Bytes
/
getuserprofile java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## Get the user profile information
After the user signs in successfully, you can use the tokens returned in the previous step to request basic user information.
```java
try {
String userInfoUrl = getNormalizedUri(issuer, "/v1/userinfo");
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setBearerAuth(tokenResponse.getAccessToken());
HttpEntity<String> requestEntity = new HttpEntity<>(null, httpHeaders);
ParameterizedTypeReference<Map<String, String>> responseType =
new ParameterizedTypeReference<Map<String, String>>() { };
ResponseEntity<Map<String, String>> responseEntity =
restTemplate.exchange(userInfoUrl, HttpMethod.GET, requestEntity, responseType);
claims = responseEntity.getBody();
Assert.notNull(claims, "claims cannot be null");
user = claims.get("preferred_username");
}
catch (Exception e) {
logger.error("Error retrieving profile from user info endpoint", e);
}
```