Ejemplo n.º 1
0
 private String getAuthorizeUrl() {
   StringBuilder url = new StringBuilder();
   url.append(this.service_.getAuthorizationEndpoint());
   boolean hasQuery = url.toString().indexOf('?') != -1;
   url.append(hasQuery ? '&' : '?')
       .append("client_id=")
       .append(Utils.urlEncode(this.service_.getClientId()))
       .append("&redirect_uri=")
       .append(Utils.urlEncode(this.service_.getGenerateRedirectEndpoint()))
       .append("&scope=")
       .append(Utils.urlEncode(this.scope_))
       .append("&response_type=code")
       .append("&state=")
       .append(Utils.urlEncode(this.oAuthState_));
   return url.toString();
 }
Ejemplo n.º 2
0
 void requestToken(String authorizationCode) {
   try {
     String url = this.service_.getTokenEndpoint();
     StringBuilder ss = new StringBuilder();
     ss.append("grant_type=authorization_code")
         .append("&client_id=")
         .append(Utils.urlEncode(this.service_.getClientId()))
         .append("&client_secret=")
         .append(Utils.urlEncode(this.service_.getClientSecret()))
         .append("&redirect_uri=")
         .append(Utils.urlEncode(this.service_.getGenerateRedirectEndpoint()))
         .append("&code=")
         .append(authorizationCode);
     HttpClient client = new HttpClient(this);
     client.setTimeout(15);
     client
         .done()
         .addListener(
             this,
             new Signal2.Listener<Exception, HttpMessage>() {
               public void trigger(Exception event1, HttpMessage event2) {
                 OAuthProcess.this.handleToken(event1, event2);
               }
             });
     Method m = this.service_.getTokenRequestMethod();
     if (m == Method.Get) {
       boolean hasQuery = url.indexOf('?') != -1;
       url += (hasQuery ? '&' : '?') + ss.toString();
       client.get(url);
     } else {
       HttpMessage post = new HttpMessage();
       post.setHeader("Content-Type", "application/x-www-form-urlencoded");
       post.addBodyText(ss.toString());
       client.post(url, post);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }