use of org.scribe.model.Verifier in project Notes by lguipeng.
the class EvernoteOAuthHelper method finishAuthorization.
public boolean finishAuthorization(Activity activity, int resultCode, Intent data) {
if (resultCode != Activity.RESULT_OK || data == null) {
return false;
}
String url = data.getStringExtra(EvernoteUtil.EXTRA_OAUTH_CALLBACK_URL);
if (TextUtils.isEmpty(url)) {
return false;
}
Uri uri = Uri.parse(url);
String verifierString = uri.getQueryParameter("oauth_verifier");
String appLnbString = uri.getQueryParameter("sandbox_lnb");
boolean isAppLinkedNotebook = !TextUtils.isEmpty(appLnbString) && "true".equalsIgnoreCase(appLnbString);
if (TextUtils.isEmpty(verifierString)) {
CAT.i("User did not authorize access");
return false;
}
Verifier verifier = new Verifier(verifierString);
try {
Token accessToken = mOAuthService.getAccessToken(mRequestToken, verifier);
String rawResponse = accessToken.getRawResponse();
String authToken = accessToken.getToken();
String noteStoreUrl = extract(rawResponse, NOTE_STORE_REGEX);
String webApiUrlPrefix = extract(rawResponse, WEB_API_REGEX);
int userId = Integer.parseInt(extract(rawResponse, USER_ID_REGEX));
String evernoteHost = mBootstrapProfile.getSettings().getServiceHost();
AuthenticationResult authenticationResult = new AuthenticationResult(authToken, noteStoreUrl, webApiUrlPrefix, evernoteHost, userId, isAppLinkedNotebook);
authenticationResult.persist();
mSession.setAuthenticationResult(authenticationResult);
return true;
} catch (Exception e) {
CAT.e("Failed to obtain OAuth access token", e);
}
return false;
}
use of org.scribe.model.Verifier in project sling by apache.
the class XingOauthAuthenticationHandler method extractCredentials.
// we need the OAuth access token and the user from XING (/v1/users/me)
@Override
public AuthenticationInfo extractCredentials(final HttpServletRequest request, final HttpServletResponse response) {
logger.debug("extract credentials");
if (oAuthService == null) {
logger.error("OAuthService is null, check configuration");
return null;
}
try {
final HttpSession httpSession = request.getSession(true);
Token accessToken = (Token) httpSession.getAttribute(OAuthConstants.ACCESS_TOKEN);
XingUser xingUser = (XingUser) httpSession.getAttribute(USER_SESSION_ATTRIBUTE_NAME);
if (accessToken == null) {
// we need the request token and verifier to get an access token
final Token requestToken = (Token) httpSession.getAttribute(OAuthConstants.TOKEN);
final String verifier = request.getParameter(OAuthConstants.VERIFIER);
if (requestToken == null || verifier == null) {
return null;
}
accessToken = oAuthService.getAccessToken(requestToken, new Verifier(verifier));
logger.debug("access token: {}", accessToken);
httpSession.setAttribute(OAuthConstants.ACCESS_TOKEN, accessToken);
}
if (xingUser == null) {
xingUser = fetchUser(accessToken);
logger.debug("xing user: {}", xingUser);
httpSession.setAttribute(USER_SESSION_ATTRIBUTE_NAME, xingUser);
}
final AuthenticationInfo authenticationInfo = new AuthenticationInfo(XingOauth.AUTH_TYPE, xingUser.getId());
authenticationInfo.put(XingOauth.AUTHENTICATION_CREDENTIALS_ACCESS_TOKEN_KEY, accessToken);
authenticationInfo.put(XingOauth.AUTHENTICATION_CREDENTIALS_USER_KEY, xingUser);
return authenticationInfo;
} catch (Exception e) {
logger.error(e.getMessage(), e);
removeAuthFromSession(request);
return null;
}
}
use of org.scribe.model.Verifier in project data-transfer-project by google.
the class FlickrAuth method generateAuthData.
@Override
public AuthData generateAuthData(String callbackBaseUrl, String authCode, UUID jobId, AuthData initialAuthData, @Nullable String extra) throws IOException {
Preconditions.checkArgument(Strings.isNullOrEmpty(extra), "Extra data not expected");
Preconditions.checkNotNull(initialAuthData, "Earlier auth data not expected for Google flow");
AuthInterface authInterface = flickr.getAuthInterface();
Token token = fromAuthData(initialAuthData);
Token requestToken = authInterface.getAccessToken(token, new Verifier(authCode));
try {
authInterface.checkToken(requestToken);
return TokenSecretAuthData.create(requestToken.getToken(), requestToken.getSecret());
} catch (FlickrException e) {
throw new IOException("Problem verifying auth token", e);
}
}
use of org.scribe.model.Verifier in project data-transfer-project by google.
the class FlickrAuth method generateAuthData.
@Override
public AuthData generateAuthData(IOInterface ioInterface) throws IOException {
AuthInterface authInterface = flickr.getAuthInterface();
Token token = authInterface.getRequestToken();
String url = authInterface.getAuthorizationUrl(token, Permission.WRITE);
String tokenKey = ioInterface.ask("Please enter the code from this authUrl: " + url);
Token requestToken = authInterface.getAccessToken(token, new Verifier(tokenKey));
try {
Auth auth = authInterface.checkToken(requestToken);
return toAuthData(requestToken);
} catch (FlickrException e) {
throw new IOException("Problem verifying auth token", e);
}
}
use of org.scribe.model.Verifier in project mamute by caelum.
the class FacebookAuthController method signupViaFacebook.
@Get("/sign-up/facebook/")
public void signupViaFacebook(String code, String state) {
if (code == null) {
includeAsList("mamuteMessages", i18n("error", "error.signup.facebook.unknown"));
redirectTo(SignupController.class).signupForm();
return;
}
Token token = service.getAccessToken(null, new Verifier(code));
SocialAPI facebookAPI = new FacebookAPI(service, token);
boolean success = loginManager.merge(MethodType.FACEBOOK, facebookAPI);
if (!success) {
includeAsList("mamuteMessages", i18n("error", "signup.errors.facebook.invalid_email", state));
result.redirectTo(AuthController.class).loginForm(state);
return;
}
redirectToRightUrl(state);
}
Aggregations