use of org.pac4j.oauth.profile.definition.OAuth10ProfileDefinition in project pac4j by pac4j.
the class YahooProfileCreator method retrieveUserProfileFromToken.
@Override
protected YahooProfile retrieveUserProfileFromToken(final WebContext context, final OAuth1AccessToken accessToken) {
// get the guid: https://developer.yahoo.com/social/rest_api_guide/introspective-guid-resource.html
final OAuth10ProfileDefinition<YahooProfile> profileDefinition = (OAuth10ProfileDefinition<YahooProfile>) configuration.getProfileDefinition();
final String profileUrl = profileDefinition.getProfileUrl(accessToken, this.configuration);
final OAuth10aService service = configuration.buildService(context, client, null);
String body = sendRequestForData(service, accessToken, profileUrl, profileDefinition.getProfileVerb());
final String guid = CommonHelper.substringBetween(body, "<value>", "</value>");
logger.debug("guid : {}", guid);
if (CommonHelper.isBlank(guid)) {
throw new HttpCommunicationException("Cannot find guid from body : " + body);
}
body = sendRequestForData(service, accessToken, "https://social.yahooapis.com/v1/user/" + guid + "/profile?format=json", Verb.GET);
final YahooProfile profile = (YahooProfile) configuration.getProfileDefinition().extractUserProfile(body);
addAccessTokenToProfile(profile, accessToken);
return profile;
}
Aggregations