Package org.scribe.oauth

Examples of org.scribe.oauth.OAuthService


            flash.error("Mauvaise requète, le provider d'authentification n'est pas indiqué");
            index(null);
        }
       
        OAuthProvider oauthProvider = OAuthProviderFactory.getProvider(provider);
        OAuthService oauthService = oauthProvider.getService();

        if (OAuth.isVerifierResponse()) {
            // We got the verifier;
            // now get the access tokens using the request tokens
            final Token requestToken = new Token(flash.get(TOKEN_KEY), flash.get(SECRET_KEY));
            final String verifier = params.get("oauth_verifier");
            try {
                Token accessToken = oauthService.getAccessToken(requestToken, new Verifier(verifier));

                // Fetch user oAuthAccount
                OAuthAccount oAuthAccount = oauthProvider.getUserAccount(accessToken.getToken(), accessToken.getSecret());
                // Retrieve existing oAuthAccount from profile
                AuthAccount account = AuthAccount.find(provider, oAuthAccount.getOAuthLogin());

                if (account != null) {
                    onSuccessfulAuthentication(account.member.login);
                } else {

                    // Pas d'account correspondant : new way of authentication
                    manageNewAuthenticationFrom(oAuthAccount);
                }
            } catch (OAuthException ex) {
                Logger.error("Authentification impossible avec " + provider + " : " + ex.getLocalizedMessage());
                flash.error("Authentification impossible");
                index(null);
            }
        }

        try {
            Token token = oauthService.getRequestToken();
            // We received the unauthorized tokens
            // we need to store them before continuing
            flash.put(TOKEN_KEY, token.getToken());
            flash.put(SECRET_KEY, token.getSecret());
            // Redirect the user to the authorization page
            redirect(oauthService.getAuthorizationUrl(token));
        } catch (OAuthException ex) {
            Logger.error("Authentification impossible avec " + provider + " : " + ex.getLocalizedMessage());
            flash.error("Authentification impossible");
            index(null);
        }
View Full Code Here


    return Index.class;
  }

  // Facebook *************************************
  public Object onSuccessFromFacebookForm() throws MalformedURLException {
    OAuthService service = new ServiceBuilder().provider(FacebookApi.class)
        .apiKey(Constants.APIKEY_FACEBOOK)
        .apiSecret(Constants.APISECRET_FACEBOOK)
        .scope(Constants.SCOPE_FACEBOOK)
        .callback(Constants.CALLBACK_FACEBOOK).build();

    // Obtain the Authorization URL
    String authorizationUrl = service.getAuthorizationUrl(null);
    return new URL(authorizationUrl);
  }
View Full Code Here

  // Google *************************************
  @InjectPage
  private Callback callbackGoogle;

  public Object onSuccessFromGoogleForm() throws MalformedURLException {
    OAuthService service = new ServiceBuilder().provider(GoogleApi.class)
        .apiKey(Constants.APIKEY_GOOGLE)
        .apiSecret(Constants.APISECRET_GOOGLE)
        .callback(Constants.CALLBACK_GOOGLE)
        .scope(Constants.SCOPE_GOOGLE).build();

    // Obtain the Request Token and the Authorization URL
    Token requestToken = service.getRequestToken();
    callbackGoogle.setRequestToken(requestToken);
    return new URL(service.getAuthorizationUrl(requestToken));
  }
View Full Code Here

    return new URL(request.getHeader("referer"));
  }

  // Facebook *************************************
  public Object onSuccessFromFacebookForm() throws MalformedURLException {
    OAuthService service = new ServiceBuilder().provider(FacebookApi.class)
        .apiKey(Constants.APIKEY_FACEBOOK)
        .apiSecret(Constants.APISECRET_FACEBOOK)
        .scope(Constants.SCOPE_FACEBOOK)
        .callback(Constants.CALLBACK_FACEBOOK).build();

    // Obtain the Authorization URL
    String authorizationUrl = service.getAuthorizationUrl(null);
    return new URL(authorizationUrl);
  }
View Full Code Here

  // Google *************************************
  @InjectPage
  private Callback callbackGoogle;

  public Object onSuccessFromGoogleForm() throws MalformedURLException {
    OAuthService service = new ServiceBuilder().provider(GoogleApi.class)
        .apiKey(Constants.APIKEY_GOOGLE)
        .apiSecret(Constants.APISECRET_GOOGLE)
        .callback(Constants.CALLBACK_GOOGLE)
        .scope(Constants.SCOPE_GOOGLE).build();

    // Obtain the Request Token and the Authorization URL
    Token requestToken = service.getRequestToken();
    callbackGoogle.setRequestToken(requestToken);
    return new URL(service.getAuthorizationUrl(requestToken));
  }
View Full Code Here

    }
    return null;
  }

  public void readGoogleKey() {
    OAuthService service = new ServiceBuilder().provider(GoogleApi.class)
        .apiKey(Constants.APIKEY_GOOGLE)
        .apiSecret(Constants.APISECRET_GOOGLE)
        .scope(Constants.SCOPE_GOOGLE)
        .callback(Constants.CALLBACK_GOOGLE).build();

    // Trade the Request Token and Verfier for the Access Token
    Token accessToken = service.getAccessToken(requestToken, verifier);

    // Now let's go and ask for a protected resource!
    OAuthRequest request = new OAuthRequest(Verb.GET,
        Constants.PROTECTED_RESOURCE_URL_GOOGLE);
    service.signRequest(accessToken, request);
    request.addHeader("GData-Version", "3.0");
    Response response = request.send();

    readDataProfile(response.getBody());
  }
View Full Code Here

    }
    return null;
  }

  public void readFacebookKey() {
    OAuthService service = new ServiceBuilder().provider(FacebookApi.class)
        .apiKey(Constants.APIKEY_FACEBOOK)
        .apiSecret(Constants.APISECRET_FACEBOOK)
        .scope(Constants.SCOPE_FACEBOOK)
        .callback(Constants.CALLBACK_FACEBOOK).build();

    // Trade the Request Token and Verfier for the Access Token
    Token accessToken = service.getAccessToken(Constants.EMPTY_TOKEN,
        verifier);

    // Now let's go and ask for a protected resource!
    OAuthRequest request = new OAuthRequest(Verb.GET,
        Constants.PROTECTED_RESOURCE_URL_FACEBOOK);
    service.signRequest(accessToken, request);
    Response response = request.send();
    readDataProfile(StringEscapeUtils.unescapeJava(response.getBody()));
  }
View Full Code Here

TOP

Related Classes of org.scribe.oauth.OAuthService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.