Skip to content

Commit 33c8832

Browse files
committed
User @AuthenticationPrincipal in getUser
1 parent 29e3e1a commit 33c8832

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

src/main/java/com/okta/developer/jugtours/web/UserController.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@ public class UserController {
2525
String issuerUri;
2626

2727
@GetMapping("/api/user")
28-
public ResponseEntity<?> getUser(Principal principal) {
29-
if (principal == null) {
28+
public ResponseEntity<?> getUser(@AuthenticationPrincipal OAuth2User user) {
29+
if (user == null) {
3030
return new ResponseEntity<>("", HttpStatus.OK);
31-
}
32-
if (principal instanceof OAuth2AuthenticationToken) {
33-
OAuth2User authentication = ((OAuth2AuthenticationToken) principal).getPrincipal();
34-
Map<String, Object> details = authentication.getAttributes();
35-
return ResponseEntity.ok().body(details);
3631
} else {
37-
return ResponseEntity.ok().body(principal.getName());
32+
return ResponseEntity.ok().body(user.getAttributes());
3833
}
3934
}
4035

0 commit comments

Comments
 (0)