1
votes

I am trying to integrate dropbox inside my application. If I use standard dropbox apis, for login it gets redirected to browser or dropbox app. I do want to navigate away from my app, so for oAuth 2.0 authentication for dropbox, I want to use webview.

Dropbox mentins that it is possible using "Implicit Grant"

https://www.dropbox.com/developers/blog/45/using-oauth-20-with-the-core-api

But I am not able not able to implement this "Implicit Grant". I am not sure what to put in the "REDIRECT URL" part of the URL I am forming.

Can someone help me with this?

1
Cross-linking for reference: forums.dropbox.com/topic.php?id=119445 - Greg

1 Answers

1
votes

You can put whatever you want in the redirect url. When the dropbox completes the authentication with the user, it will try to load the REDIRECT_URI you submitted but before that, a WebViewClient will capture that redirect.

webview.setWebViewClient(new WebViewClient() {
           @Override
           public boolean shouldOverrideUrlLoading(WebView view, String url) {
               ...
               if ( url.startsWith(REDIRECT_URI) ) {

                  // extract OAuth2 access_token appended in url
                  if ( url.indexOf("access_token=") != -1 ) {
                       accessToken = mExtractToken(url);

                       // store in default SharedPreferences
                       Editor e = getPreferences(Context.MODE_PRIVATE).edit();
                       e.putString(SHPREF_KEY_ACCESS_TOKEN, accessToken);
                       e.commit();
                   }

               // don't go to redirectUri
               return true;
               }

               // load the webpage from url: login and grant access
               return super.shouldOverrideUrlLoading(view, url); // return false;
           }
       });

Got the code from http://techblog.constantcontact.com/software-development/implementing-oauth2-0-in-an-android-app/ .