use of org.scribe.model.Verifier in project muikku by otavanopisto.
the class GoogleAuthenticationStrategy 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);
GoogleAccessToken googleAccessToken;
try {
googleAccessToken = objectMapper.readValue(accessToken.getRawResponse(), GoogleAccessToken.class);
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
calendar.add(Calendar.SECOND, googleAccessToken.getExpiresIn());
Date expires = calendar.getTime();
sessionController.addOAuthAccessToken("google", expires, accessToken.getToken(), null);
} catch (IOException e) {
logger.log(Level.SEVERE, "Token extraction failed a JSON parsing error", e);
return new AuthenticationResult(AuthenticationResult.Status.ERROR);
}
List<String> scopesList = Arrays.asList(requestedScopes);
boolean hasProfileScope = scopesList.contains("https://www.googleapis.com/auth/userinfo.profile");
GoogleUserInfo userInfo = null;
if (hasProfileScope) {
OAuthRequest request = new OAuthRequest(Verb.GET, "https://www.googleapis.com/oauth2/v1/userinfo?alt=json");
service.signRequest(accessToken, request);
Response response = request.send();
try {
userInfo = objectMapper.readValue(response.getBody(), GoogleUserInfo.class);
} catch (IOException e) {
logger.log(Level.SEVERE, "Logging in failed because of a JSON parsing exception", e);
return new AuthenticationResult(AuthenticationResult.Status.ERROR);
}
}
if (userInfo != null)
return processLogin(authSource, requestParameters, userInfo.getId(), Arrays.asList(userInfo.getEmail()), userInfo.getGivenName(), userInfo.getFamilyName());
else {
return new AuthenticationResult(AuthenticationResult.Status.GRANT);
}
}
use of org.scribe.model.Verifier in project muikku by otavanopisto.
the class FacebookAuthenticationStrategy 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);
FacebookUser meObject = null;
OAuthRequest request = new OAuthRequest(Verb.GET, "https://graph.facebook.com/me");
service.signRequest(accessToken, request);
Response response = request.send();
try {
meObject = objectMapper.readValue(response.getBody(), FacebookUser.class);
} catch (IOException e) {
logger.log(Level.SEVERE, "Logging in failed because of a JSON parsing exception", e);
return new AuthenticationResult(AuthenticationResult.Status.ERROR);
}
Integer expiresIn = extractExpires(accessToken);
Date expires = null;
if (expiresIn != null) {
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
calendar.add(Calendar.SECOND, expiresIn);
expires = calendar.getTime();
sessionController.addOAuthAccessToken("facebook", expires, accessToken.getToken(), null);
}
if (meObject != null)
return processLogin(authSource, requestParameters, meObject.getId(), Arrays.asList(meObject.getEmail()), meObject.getFirstName(), meObject.getLastName());
else {
return new AuthenticationResult(AuthenticationResult.Status.GRANT);
}
}
use of org.scribe.model.Verifier in project camel by apache.
the class YammerAccessCodeGenerator method main.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Paste the consumerKey here");
System.out.print(">>");
String apiKey = in.nextLine();
System.out.println("Paste the consumerSecret here");
System.out.print(">>");
String apiSecret = in.nextLine();
OAuthService service = new ServiceBuilder().provider(YammerApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Go and authorize your app here (eg. in a web browser):");
System.out.println(authorizationUrl);
System.out.println("... and paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Your Access Token is: " + accessToken);
System.out.println();
in.close();
}
use of org.scribe.model.Verifier in project data-transfer-project by google.
the class FlickrAuthDataGenerator method generateAuthData.
@Override
public AuthData generateAuthData(String callbackBaseUrl, String authCode, String id, AuthData initialAuthData, String extra) {
Preconditions.checkArgument(Strings.isNullOrEmpty(extra), "Extra data not expected");
Preconditions.checkNotNull(initialAuthData, "Earlier auth data not expected for Flickr flow");
AuthInterface authInterface = flickr.getAuthInterface();
Token token = fromAuthData(initialAuthData);
Token requestToken = authInterface.getAccessToken(token, new Verifier(authCode));
try {
authInterface.checkToken(requestToken);
} catch (FlickrException e) {
logger.warn("Problem verifying auth token {}", e);
return null;
}
return new TokenSecretAuthData(requestToken.getToken(), requestToken.getSecret());
}
use of org.scribe.model.Verifier in project mamute by caelum.
the class GoogleAuthController method signUpViaGoogle.
@Get("/sign-up/google/")
public void signUpViaGoogle(String state, String code) {
Token token = service.getAccessToken(null, new Verifier(code));
SocialAPI googleAPI = new GoogleAPI(token, service);
loginManager.merge(MethodType.GOOGLE, googleAPI);
redirectToRightUrl(state);
}
Aggregations