Search in sources :

Example 1 with Verifier

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;
}
Also used : Token(org.scribe.model.Token) Verifier(org.scribe.model.Verifier) Uri(android.net.Uri) OAuthException(org.scribe.exceptions.OAuthException)

Example 2 with Verifier

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;
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) Token(org.scribe.model.Token) XingUser(org.apache.sling.auth.xing.api.XingUser) Verifier(org.scribe.model.Verifier) AuthenticationInfo(org.apache.sling.auth.core.spi.AuthenticationInfo) IOException(java.io.IOException)

Example 3 with Verifier

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);
    }
}
Also used : AuthInterface(com.flickr4java.flickr.auth.AuthInterface) FlickrException(com.flickr4java.flickr.FlickrException) Token(org.scribe.model.Token) IOException(java.io.IOException) Verifier(org.scribe.model.Verifier)

Example 4 with Verifier

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);
    }
}
Also used : AuthInterface(com.flickr4java.flickr.auth.AuthInterface) FlickrException(com.flickr4java.flickr.FlickrException) Auth(com.flickr4java.flickr.auth.Auth) Token(org.scribe.model.Token) IOException(java.io.IOException) Verifier(org.scribe.model.Verifier)

Example 5 with Verifier

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);
}
Also used : FacebookAPI(org.mamute.auth.FacebookAPI) Token(org.scribe.model.Token) Verifier(org.scribe.model.Verifier) SocialAPI(org.mamute.auth.SocialAPI) Get(br.com.caelum.vraptor.Get)

Aggregations

Verifier (org.scribe.model.Verifier)15 Token (org.scribe.model.Token)14 IOException (java.io.IOException)8 OAuthRequest (org.scribe.model.OAuthRequest)4 Response (org.scribe.model.Response)4 FlickrException (com.flickr4java.flickr.FlickrException)3 AuthInterface (com.flickr4java.flickr.auth.AuthInterface)3 AuthenticationResult (fi.otavanopisto.muikku.auth.AuthenticationResult)3 Calendar (java.util.Calendar)3 Date (java.util.Date)3 GregorianCalendar (java.util.GregorianCalendar)3 HttpSession (javax.servlet.http.HttpSession)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 OAuthService (org.scribe.oauth.OAuthService)3 Uri (android.net.Uri)2 Get (br.com.caelum.vraptor.Get)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ServletException (javax.servlet.ServletException)2 SocialAPI (org.mamute.auth.SocialAPI)2 UserRequest (org.olat.core.gui.UserRequest)2