Search in sources :

Example 21 with OAuthRequest

use of org.scribe.model.OAuthRequest in project muikku by otavanopisto.

the class PyramusAuthenticationStrategy method processResponse.

@Override
protected AuthenticationResult processResponse(AuthSource authSource, Map<String, String[]> requestParameters, OAuthService service, String[] requestedScopes) {
    ObjectMapper objectMapper = new ObjectMapper();
    String verifier = getFirstRequestParameter(requestParameters, "code");
    Verifier v = new Verifier(verifier);
    Token accessToken = service.getAccessToken(null, v);
    PyramusAccessToken pyramusAccessToken;
    try {
        pyramusAccessToken = objectMapper.readValue(accessToken.getRawResponse(), PyramusAccessToken.class);
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        calendar.add(Calendar.SECOND, pyramusAccessToken.getExpiresIn());
        Date expires = calendar.getTime();
        sessionController.addOAuthAccessToken("pyramus", expires, accessToken.getToken(), pyramusAccessToken.getRefreshToken());
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Token extraction failed a JSON parsing error", e);
        return new AuthenticationResult(AuthenticationResult.Status.ERROR);
    }
    WhoAmI whoAmI = null;
    OAuthRequest request = new OAuthRequest(Verb.GET, getWhoAmIUrl());
    service.signRequest(accessToken, request);
    Response response = request.send();
    try {
        whoAmI = objectMapper.readValue(response.getBody(), WhoAmI.class);
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Logging in failed because of a JSON parsing exception", e);
        return new AuthenticationResult(AuthenticationResult.Status.ERROR);
    }
    return processLogin(authSource, requestParameters, whoAmI.getId().toString(), whoAmI.getEmails(), whoAmI.getFirstName(), whoAmI.getLastName());
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Token(org.scribe.model.Token) IOException(java.io.IOException) Verifier(org.scribe.model.Verifier) Date(java.util.Date) AuthenticationResult(fi.otavanopisto.muikku.auth.AuthenticationResult) Response(org.scribe.model.Response) WhoAmI(fi.otavanopisto.pyramus.rest.model.WhoAmI) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 22 with OAuthRequest

use of org.scribe.model.OAuthRequest in project openolat by klemens.

the class TequilaProvider method getUser.

@Override
public OAuthUser getUser(OAuthService service, Token accessToken) {
    String endpoint = oauthModule.getTequilaOAuth2Endpoint();
    if (!endpoint.endsWith("/")) {
        endpoint += "/";
    }
    OAuthRequest request = new OAuthRequest(Verb.GET, endpoint + "userinfo");
    service.signRequest(accessToken, request);
    request.addHeader("Accept", "application/json");
    Response oauthResponse = request.send();
    String body = oauthResponse.getBody();
    return parseResponse(body);
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Response(org.scribe.model.Response)

Example 23 with OAuthRequest

use of org.scribe.model.OAuthRequest in project openolat by klemens.

the class TwitterProvider method getUser.

@Override
public OAuthUser getUser(OAuthService service, Token accessToken) {
    OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, "https://api.twitter.com/1.1/account/verify_credentials.json");
    service.signRequest(accessToken, oauthRequest);
    Response oauthResponse = oauthRequest.send();
    String body = oauthResponse.getBody();
    return parseInfos(body);
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Response(org.scribe.model.Response)

Example 24 with OAuthRequest

use of org.scribe.model.OAuthRequest in project openolat by klemens.

the class Google2Provider method getUser.

@Override
public OAuthUser getUser(OAuthService service, Token accessToken) {
    OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, "https://www.googleapis.com/oauth2/v2/userinfo");
    service.signRequest(accessToken, oauthRequest);
    Response oauthResponse = oauthRequest.send();
    String body = oauthResponse.getBody();
    return parseInfos(body);
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Response(org.scribe.model.Response)

Example 25 with OAuthRequest

use of org.scribe.model.OAuthRequest in project openolat by klemens.

the class LinkedInProvider method getUser.

@Override
public OAuthUser getUser(OAuthService service, Token accessToken) {
    OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, "http://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address)");
    service.signRequest(accessToken, oauthRequest);
    Response oauthResponse = oauthRequest.send();
    String body = oauthResponse.getBody();
    return parseInfos(body);
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Response(org.scribe.model.Response)

Aggregations

OAuthRequest (org.scribe.model.OAuthRequest)25 Response (org.scribe.model.Response)24 IOException (java.io.IOException)6 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)6 Date (java.util.Date)5 Token (org.scribe.model.Token)4 Verifier (org.scribe.model.Verifier)4 AuthenticationResult (fi.otavanopisto.muikku.auth.AuthenticationResult)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 JSONObject (org.json.JSONObject)3 OAuthException (org.scribe.exceptions.OAuthException)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Contributor (ai.elimu.model.Contributor)1 SignOnEvent (ai.elimu.model.contributor.SignOnEvent)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 WhoAmI (fi.otavanopisto.pyramus.rest.model.WhoAmI)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1