use of org.orcid.core.oauth.openid.OpenIDConnectUserInfo in project ORCID-Source by ORCID.
the class OpenIDController method getUserInfo.
/** Manually checks bearer token, looks up user or throws 403.
*
* @return
*/
@RequestMapping(value = "/oauth/userinfo", method = { RequestMethod.GET, RequestMethod.POST }, produces = "application/json")
@ResponseBody
public ResponseEntity<OpenIDConnectUserInfo> getUserInfo(HttpServletRequest request) {
//note we do not support form post per https://tools.ietf.org/html/rfc6750 because it's a MAY and pointless
String authHeader = request.getHeader("Authorization");
if (authHeader != null) {
//lookup token, check it's valid, check scope.
String tokenValue = authHeader.replace("Bearer", "").trim();
OAuth2AccessToken tok = tokenStore.readAccessToken(tokenValue);
if (tok != null && !tok.isExpired()) {
boolean hasScope = false;
Set<ScopePathType> requestedScopes = ScopePathType.getScopesFromStrings(tok.getScope());
for (ScopePathType scope : requestedScopes) {
if (scope.hasScope(ScopePathType.OPENID)) {
hasScope = true;
}
}
if (hasScope) {
String orcid = tok.getAdditionalInformation().get("orcid").toString();
Person person = personDetailsManagerReadOnly.getPublicPersonDetails(orcid);
return ResponseEntity.ok(new OpenIDConnectUserInfo(orcid, person));
}
}
}
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
Aggregations