Package org.scribe.model

Examples of org.scribe.model.OAuthRequest


           
          final String code = request.getParameter("code");
          if(StringUtils.isNotEmpty(code)){
            Verifier verifier = new Verifier(code);
            Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
            OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, FACEBOOK_ME_URL);
              service.signRequest(accessToken, oauthRequest);
              Response oauthResponse = oauthRequest.send();
              int responseCode = oauthResponse.getCode();
              String responseBody = oauthResponse.getBody();
             
              if(responseCode == 200){
                handleAuthenticationData(request, response, requestData, OAuthType.FACEBOOK, responseBody);
View Full Code Here


            this.config = config;
        }
       
        @Override
        public Token getAccessToken(Token requestToken, Verifier verifier) {
            OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
            switch (api.getAccessTokenVerb()) {
            case POST:
                request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
                request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
                request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
                request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
                request.addBodyParameter(GRANT_TYPE, GRANT_TYPE_AUTHORIZATION_CODE);
                break;
            case GET:
            default:
                request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
                request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
                request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
                request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
                if(config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
            }
            Response response = request.send();
            return api.getAccessTokenExtractor().extract(response.getBody());
        }
View Full Code Here

        this.addGrantType = addGrantType;
    }
   
    @Override
    public Token getAccessToken(final Token requestToken, final Verifier verifier) {
        final OAuthRequest request = new ProxyOAuthRequest(this.api.getAccessTokenVerb(),
                                                           this.api.getAccessTokenEndpoint(), this.connectTimeout,
                                                           this.readTimeout, this.proxyHost, this.proxyPort);
        if (this.getParameter) {
            request.addQuerystringParameter(OAuthConstants.CLIENT_ID, this.config.getApiKey());
            request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, this.config.getApiSecret());
            request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
            request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, this.config.getCallback());
            if (this.config.hasScope()) {
                request.addQuerystringParameter(OAuthConstants.SCOPE, this.config.getScope());
            }
            if (this.addGrantType) {
                request.addQuerystringParameter("grant_type", "authorization_code");
            }
        } else {
            request.addBodyParameter(OAuthConstants.CLIENT_ID, this.config.getApiKey());
            request.addBodyParameter(OAuthConstants.CLIENT_SECRET, this.config.getApiSecret());
            request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
            request.addBodyParameter(OAuthConstants.REDIRECT_URI, this.config.getCallback());
            if (this.config.hasScope()) {
                request.addBodyParameter(OAuthConstants.SCOPE, this.config.getScope());
            }
            if (this.addGrantType) {
                request.addBodyParameter("grant_type", "authorization_code");
            }
        }
        final Response response = request.send();
        return this.api.getAccessTokenExtractor().extract(response.getBody());
    }
View Full Code Here

    }
   
    @Override
    public Token getRequestToken() {
        this.config.log("obtaining request token from " + this.api.getRequestTokenEndpoint());
        final OAuthRequest request = new ProxyOAuthRequest(this.api.getRequestTokenVerb(),
                                                           this.api.getRequestTokenEndpoint(), this.connectTimeout,
                                                           this.readTimeout, this.proxyHost, this.proxyPort);
       
        this.config.log("setting oauth_callback to " + this.config.getCallback());
        request.addOAuthParameter(OAuthConstants.CALLBACK, this.config.getCallback());
        addOAuthParams(request, OAuthConstants.EMPTY_TOKEN);
        appendSignature(request);
       
        this.config.log("sending request...");
        final Response response = request.send();
        final String body = response.getBody();
       
        this.config.log("response status code: " + response.getCode());
        this.config.log("response body: " + body);
        return this.api.getRequestTokenExtractor().extract(body);
View Full Code Here

    }
   
    private String send(Verb verb, String params) throws Exception {
        String url = apiUrl + ((params != null) ? params : "");
       
        OAuthRequest request = new OAuthRequest(verb, url);
        request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, apiAccessToken);
       
        // For more details on the “Bearer” token refer to http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-23
        StringBuilder sb = new StringBuilder();
        sb.append("Bearer ");
        sb.append(apiAccessToken);
        request.addHeader("Authorization",  sb.toString());

        if (LOG.isDebugEnabled()) {
            LOG.debug("Yammer request url: {}", request.getCompleteUrl());
        }
       
        Response response = request.send();
        if (response.isSuccessful()) {                   
            return response.getBody();
        } else {
            throw new Exception(String.format("Failed to poll %s. Got response code %s and body: %s", getApiUrl(), response.getCode(), response.getBody()));
        }
View Full Code Here

    private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/me";
  public static final String FACEBOOK_ACCESS_TOKEN_SESSION = "FACEBOOK_ACCESS_TOKEN_SESSION";

  public static void saveAccessToken(HttpServletRequest request, OAuthService service, Token accessToken) throws Exception {
   
        OAuthRequest _request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
        service.signRequest(accessToken, _request);
        Response _response = _request.send();
        if (_response.getCode() != 200)
          throw new OAuthException("Can query account information.");

        String contentType = _response.getHeader("Content-Type");
    if (contentType == null) contentType = "";
View Full Code Here

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

    private static final String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/oauth2/v1/userinfo";
  public static final String GOOGLE_ACCESS_TOKEN_SESSION = "GOOGLE_ACCESS_TOKEN_SESSION";

  public static void saveAccessToken(HttpServletRequest request, OAuthService service, Token accessToken) throws Exception {
   
        OAuthRequest _request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
        service.signRequest(accessToken, _request);
        Response _response = _request.send();
        if (_response.getCode() != 200)
          throw new OAuthException("Can query account information.");

        String contentType = _response.getHeader("Content-Type");
    if (contentType == null) contentType = "";
View Full Code Here

        String url = DEFAULT_ENDPOINT+"/user?oauth_token=";
        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();

        if (httpResponseCode==200) {
            JSONObject jsonObject = JSONObject.fromObject(body);
            String fitnessActivities = jsonObject.getString("fitness_activities");
            List<String> activities = new ArrayList<String>();
            String activityFeedURL = DEFAULT_ENDPOINT + fitnessActivities;
            countSuccessfulApiCall(updateInfo.apiKey, updateInfo.objectTypes, then, request.getCompleteUrl());

            getFitnessActivityFeed(updateInfo, service, token, activityFeedURL, 25, activities, since);
            Collections.reverse(activities);
            getFitnessActivities(updateInfo, service, token, activities);
        } else {
            countFailedApiCall(updateInfo.apiKey, updateInfo.objectTypes, then,
                               request.getCompleteUrl(), ExceptionUtils.getStackTrace(new Exception()),
                               httpResponseCode, body);
            if (httpResponseCode==403) {
                handleTokenRevocation(body);
            }
            if (httpResponseCode>=400&&httpResponseCode<500)
View Full Code Here

                                      final Token token, final List<String> activities) throws Exception {
        for (String activity : activities) {
            if (guestService.getApiKey(updateInfo.apiKey.getId())==null)
                break;
            String activityURL = DEFAULT_ENDPOINT + activity;
            OAuthRequest request = new OAuthRequest(Verb.GET, activityURL);
            request.addQuerystringParameter("oauth_token", token.getToken());
            request.addHeader("Accept", "application/vnd.com.runkeeper.FitnessActivity+json");
            service.signRequest(token, request);
            long then = System.currentTimeMillis();
            Response response = request.send();
            final int httpResponseCode = response.getCode();
            String body = response.getBody();
            if (httpResponseCode ==200) {
                countSuccessfulApiCall(updateInfo.apiKey,
                                       updateInfo.objectTypes, then, activityURL);
View Full Code Here

TOP

Related Classes of org.scribe.model.OAuthRequest

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.