use of org.forgerock.oauth2.core.exceptions.OAuth2Exception in project OpenAM by OpenRock.
the class UserInfoServiceImpl method getUserInfo.
/**
* {@inheritDoc}
*/
public JsonValue getUserInfo(OAuth2Request request) throws OAuth2Exception {
AccessTokenVerifier.TokenState headerToken = headerTokenVerifier.verify(request);
AccessTokenVerifier.TokenState formToken = formTokenVerifier.verify(request);
if (!headerToken.isValid() && !formToken.isValid()) {
logger.debug("No access token provided for this request.");
throw new InvalidTokenException();
}
if (headerToken.isValid() && formToken.isValid()) {
logger.debug("Access token provided in both form and header.");
throw new ServerException("Access Token cannot be provided in both form and header");
}
final String tokenId = headerToken.isValid() ? headerToken.getTokenId() : formToken.getTokenId();
final AccessToken token = tokenStore.readAccessToken(request, tokenId);
final OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(request);
return new JsonValue(providerSettings.getUserInfo(token, request).getValues());
}
Aggregations