Search in sources :

Example 1 with OAuth10ProfileDefinition

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;
}
Also used : OAuth10ProfileDefinition(org.pac4j.oauth.profile.definition.OAuth10ProfileDefinition) HttpCommunicationException(org.pac4j.core.exception.HttpCommunicationException) OAuth10aService(com.github.scribejava.core.oauth.OAuth10aService)

Aggregations

OAuth10aService (com.github.scribejava.core.oauth.OAuth10aService)1 HttpCommunicationException (org.pac4j.core.exception.HttpCommunicationException)1 OAuth10ProfileDefinition (org.pac4j.oauth.profile.definition.OAuth10ProfileDefinition)1