use of org.scribe.model.Response 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());
}
use of org.scribe.model.Response 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);
}
use of org.scribe.model.Response 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);
}
use of org.scribe.model.Response 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);
}
use of org.scribe.model.Response 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);
}
Aggregations