Package org.scribe.oauth

Examples of org.scribe.oauth.OAuthService


        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();
    }
View Full Code Here


                String consumerKey = prop.getProperty("oauth.consumer.key");
                String consumerSecret = prop.getProperty("oauth.consumer.secret");
                in.close();

    System.setProperty("debug", "true");
    OAuthService service = new ServiceBuilder()
          .provider(KivaApi.class)
          .apiKey(consumerKey)
          .apiSecret(consumerSecret)
                .callback("oob")
          .debug()
          .build();
    Token token = service.getRequestToken();
  }
View Full Code Here

        String path = request.getPathInfo().replace("/", "");
       
        if (OAuthRealm.LOG.isTraceEnabled())
          OAuthRealm.LOG.trace("the " + request.getMethod() + " method, path info "+path);
       
        OAuthService service =
        OAuthRealm._.getServiceBulderByPath(path)
          .getServiceBuilder()
          .callback(request.getRequestURL().toString())
          .build();
       
        if (request.getParameterMap().containsKey(RETURN_TO_PAGE)) {

          String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
         
          request.getSession().setAttribute(RETURN_TO_PAGE, request.getParameter(RETURN_TO_PAGE));

          response.sendRedirect(authorizationUrl);
          return;
        }
       
        String verification = request.getParameter("code");
       
        Verifier verifier = new Verifier(verification);
        Token accessToken = null;
        //workaround google API
        if (OAuthRealm._.getServiceBulderByPath(path).provider.equalsIgnoreCase("google")) {
          Google2Api api = new Google2Api();
         
          Service config = OAuthRealm._.getServiceBulderByPath(path);

          OAuthRequest req = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
          req.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
          req.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
          req.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
    // jetty.port.jetty
          req.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getReturnURL());
          req.addBodyParameter("grant_type", "authorization_code");
         
          String responce = req.send().getBody();

          JSONTokener tokener = new JSONTokener(responce);
          try {
              JSONObject root = new JSONObject(tokener);
              String access_token = root.getString("access_token");

              String token = OAuthEncoder.decode(access_token);
              accessToken = new Token(token, "", responce);

          } catch (JSONException e) {
              throw new IOException(e);
          }
         
          //accessToken = api.getAccessTokenExtractor().extract(req.send().getBody());
        } else
            accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
       
        try {
            OAuthRealm._.getServiceBulderByPath(path).saveAccessToken(request, service, accessToken);
        } catch (Exception e) {
            throw new ServletException(e);
View Full Code Here

    EntityManager em;

    @RequestMapping(value = "/token")
    public String getEvernoteToken(HttpServletRequest request) throws IOException, ServletException {
        final Boolean sandbox = Boolean.valueOf(env.get(EVERNOTE_SANDBOX_KEY));
        OAuthService service = new ServiceBuilder()
                .provider(sandbox?EvernoteApi.Sandbox.class:EvernoteApi.class)
                .apiKey(getConsumerKey())
                .apiSecret(getConsumerSecret())
                .callback(env.get("homeBaseUrl") + "evernote/upgradeToken")
                .build();
        request.getSession().setAttribute(EVERNOTE_SERVICE, service);

        // Obtain the Authorization URL
        Token requestToken = service.getRequestToken();
        request.getSession().setAttribute(EVERNOTE_REQUEST_TOKEN, requestToken);
        String authorizationUrl = service.getAuthorizationUrl(requestToken);
        final String apiKeyIdParameter = request.getParameter("apiKeyId");
        if (apiKeyIdParameter!=null)
            request.getSession().setAttribute(EVERNOTE_RENEWTOKEN_APIKEYID, apiKeyIdParameter);

        return "redirect:" + authorizationUrl;
View Full Code Here

    @RequestMapping(value = "/upgradeToken")
    public String upgradeToken(HttpServletRequest request) throws IOException {
        final String code = request.getParameter("oauth_verifier");
        Verifier verifier = new Verifier(code);
        OAuthService service = (OAuthService)request.getSession().getAttribute(EVERNOTE_SERVICE);

        Token requestToken = (Token)request.getSession().getAttribute(EVERNOTE_REQUEST_TOKEN);
        Token accessToken = service.getAccessToken(requestToken, verifier);

        final String token = accessToken.getToken();

        Guest guest = AuthHelper.getGuest();
View Full Code Here

        final String accessToken = guestService.getApiKeyAttribute(updateInfo.apiKey, "accessToken");
        final Token token = new Token(accessToken, guestService.getApiKeyAttribute(updateInfo.apiKey, "runkeeperConsumerSecret"));
        final String userEndpoint = url + accessToken;
        OAuthRequest request = new OAuthRequest(Verb.GET, userEndpoint);
        request.addHeader("Accept", "application/vnd.com.runkeeper.User+json");
        final OAuthService service = runKeeperController.getOAuthService();
        service.signRequest(token, request);
        Response response = request.send();
        final int httpResponseCode = response.getCode();
        long then = System.currentTimeMillis();
        String body = response.getBody();
View Full Code Here

    private static final Token EMPTY_TOKEN = null;

    @RequestMapping(value = "/token")
    public String getRunkeeperToken(HttpServletRequest request) throws IOException, ServletException {

        OAuthService service = getOAuthService(request);
        request.getSession().setAttribute(RUNKEEPER_SERVICE, service);

        // Obtain the Authorization URL
        String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
        if (request.getParameter("apiKeyId") != null)
            authorizationUrl += authorizationUrl.indexOf("?")!=-1
                             ? "&state=" + request.getParameter("apiKeyId")
                             : "?state=" + request.getParameter("apiKeyId");
View Full Code Here

    @RequestMapping(value = "/upgradeToken")
    public String upgradeToken(HttpServletRequest request) throws IOException {
        final String code = request.getParameter("code");
        Verifier verifier = new Verifier(code);
        OAuthService service = (OAuthService)request.getSession().getAttribute(RUNKEEPER_SERVICE);

        Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
        final String token = accessToken.getToken();

        Guest guest = AuthHelper.getGuest();
        final Connector connector = Connector.getConnector("runkeeper");
        ApiKey apiKey;
View Full Code Here

            OAuthRequest request = new OAuthRequest(Verb.GET, url);
            for (String parameterName : parameters.keySet()) {
                request.addQuerystringParameter(parameterName,
                                                parameters.get(parameterName));
            }
            OAuthService service = getOAuthService(updateInfo.apiKey);
            final String accessToken = guestService.getApiKeyAttribute(updateInfo.apiKey, "accessToken");
            final Token token = new Token(accessToken, guestService.getApiKeyAttribute(updateInfo.apiKey, "tokenSecret"));
            service.signRequest(token, request);
            Response response = request.send();
            httpResponseCode = response.getCode();
            if (httpResponseCode!=200)
                throw new UpdateFailedException("Unexpected response code: " + httpResponseCode);
            String json = response.getBody();
View Full Code Here

    private void finishHandshakeAndSetRealOauthTokens(Connection connection) {
        ConnectionCredentials credentials = connection.getCredentials();
        OAuthEnabledConnectionProvider oauthProvider =
                connectionProviderFactory.oauthEnabledConnectionProviderFromId(connection.getProviderId());
        OAuthService oAuthService = oauthProvider.getOAuthService();
        Token requestToken = cacheService.retrieveAndRemoveToken(credentials.getOauthToken());
        Token token = oAuthService.getAccessToken(requestToken, new Verifier(credentials.getOauthVerifier()));
        oauthProvider.updateCredentials(credentials, token);
    }
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.