2013-08-09 2 views
3

Ok, j'abandonne. Quelqu'un a-t-il l'expérience de l'utilisation de IssueAuthToken et de MergeSession de Google pour s'authentifier auprès de certains services Google qui n'ont pas d'accès officiel à l'API? Dans ce cas, j'essaie d'obtenir des favoris Google (sur google.com/bookmarks).Android: Google Authentication + Ubertoken

Je reçois le SID et LSID en utilisant getAuthToken et cela fonctionne très bien. J'appelle alors

Uri ISSUE_AUTH_TOKEN_URL = Uri.parse("https://accounts.google.com/IssueAuthToken?service=bookmarks&Session=false"); 

String url = ISSUE_AUTH_TOKEN_URL.buildUpon() 
       .appendQueryParameter("SID", sid) 
       .appendQueryParameter("LSID", lsid) 
       .build().toString(); 

Je reçois le "ubertoken".

je puis faire une requête GET à MergeSession et c'est là où tout va mal:

String url2 = "https://accounts.google.com/MergeSession?source=chrome&uberauth="+uberToken+"&service=bookmarks&continue=https%3A%2F%2Fwww.google.com%2Fbookmarks%2F"; 
HttpGet getCookies = new HttpGet(url2); 

En regardant à travers les en-têtes de getCookies Je ne suis pas voir les biscuits supplémentaires je voir, et je vois aussi des choses comme X-Frame-Options: DENY .

Aide (s'il vous plaît)!

Répondre

0

Bon amis, nous y voilà. Il semble que ce qui précède soit maintenant peu fiable/cassé au moins de temps en temps en août 2013. C'est comme ça que je le fais maintenant et ça semble fonctionner. Il essaie d'abord ce qui précède, et s'il échoue, passe à la méthode n ° 2.

final Account acct = am.getAccountsByType("com.google")[acctid]; 
    final String tokenType = "weblogin:service=bookmarks&continue=https://www.google.com/bookmarks/"; 

    am.getAuthToken(acct, tokenType, null, this, new AccountManagerCallback<Bundle>() { 
     @Override 
     public void run(AccountManagerFuture<Bundle> future) { 
      try { 
       final String accessToken = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); 
       if (accessToken.contains("WILL_NOT_SIGN_IN")) { 
        am.getAuthToken(acct, "SID", null, MainActivity.this, new AccountManagerCallback<Bundle>() { 
         @Override 
         public void run(AccountManagerFuture<Bundle> future) { 
          try { 
           sid = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); 
          } catch (OperationCanceledException e) { 
           finish(); 
          } catch (Exception e) { 
           e.printStackTrace(); 
          } 

          am.getAuthToken(acct, "LSID", null, MainActivity.this, new AccountManagerCallback<Bundle>() { 
           @Override 
           public void run(AccountManagerFuture<Bundle> future) { 
            try { 
             lsid = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); 
            } catch (OperationCanceledException e) { 
             finish(); 
            } catch (Exception e) { 
             e.printStackTrace(); 
            } 

            Thread t = new Thread() { 
             public void run() { 
              try { 
               Uri ISSUE_AUTH_TOKEN_URL = Uri.parse("https://www.google.com/accounts/IssueAuthToken?service=gaia&Session=false"); 
               Uri TOKEN_AUTH_URL = Uri.parse("https://www.google.com/accounts/TokenAuth"); 

               final HttpClient httpclient = new DefaultHttpClient(); 
               httpclient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); 
               httpclient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true); 

               String url = ISSUE_AUTH_TOKEN_URL.buildUpon().appendQueryParameter("SID", sid).appendQueryParameter("LSID", lsid).build().toString(); 
               HttpPost getUberToken = new HttpPost(url); 
               HttpResponse response = httpclient.execute(getUberToken); 

               String uberToken = EntityUtils.toString(response.getEntity(), "UTF-8"); 

               final String accessToken2 = TOKEN_AUTH_URL.buildUpon() 
                 .appendQueryParameter("source", "android-browser") 
                 .appendQueryParameter("auth", uberToken) 
                 .appendQueryParameter("continue", "https://www.google.com/bookmarks/").build().toString(); 

               //do stuff 
              } catch (Exception e) { 
               e.printStackTrace(); 
              } 
             } 
            }; 
            t.start(); 
           } 
          }, null); 
         } 
        }, null); 
       } else {    
        //do stuff 
       } 
      } catch (OperationCanceledException e) { 
       finish(); 
      } catch (Exception e) { 
       finish();     
      } 
     } 
    }, null);