cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: URI HTTPS request

URI HTTPS request

Mark L.45
Collaborator | Level 8

Hi,

I am trying to follow this dropbox tutorial; but with success

https://blogs.dropbox.com/developers/2013/07/using-oauth-2-0-with-the-core-api/

I tried this call using the parameters shown and it worked, at least tried to redirect me to the localhost. But what does this mean? I simply want to be able to ask a user of app to grant dropbox permission to access a shared directory within their dropbox, so I need their bearer-id in calls my app makes to dropbox.

I setup my own authorisation key thru the dropbox, but what prey ask is a URI in this context? what can use as a redirect URL in this call, assuming I have no plans to set up a web server behind this; its an app that is making this call and I am more than happy to redirect users to dropbox if need be to get the credentials to continue?

https://www.dropbox.com/1/oauth2/authorize?client_id=<appkey>&response_type=code&redirect_uri=<redirect URI>&state=<CSRF token>

client_id I have?
redirect URI I don't have; I set it to https://localhost in my app, but it makes no sense?
CSRF token I can generate?

I am looking to do an “implicit grant” (for client-side apps like mobile or JavaScript apps). I don't want to have to try to implement Swifty API if I can avoid doing so since I want my code to be as simple as possible?

--- posted and partly answered...

If you want to use the implicit flow, your response_type should be set to "token". The client_id should be your app key, and the redirect URI should be some URI where you want the user sent back to after they approve your app to connect to their account. For the implicit a.k.a. token flow, the access token is returned to the redirect URI on the URL fragment.

While in development, you may use localhost, which points to your local machine, to handle the redirect. You may also want to use localhost in general if your app only runs on the client.

There's an OAuth guide here that may be useful:

https://www.dropbox.com/developers/reference/oauthguide

Which I did, but now it is telling me it cannot open the URL I gave it, localhosts; which makes sense cause it isn't a real URL? Do I simply process the result in the https returned?

On that note I still missed something here? If my app that is making this call needs to access the local dropbox, how do I get the client-id with asking the client to visit dropbox and fetch this technical string; a app killer of a setup. I??

10 Replies 10

Mark L.45
Collaborator | Level 8

Thanks Steve. I like the comment, your code will break 🙂 straight to the point. Reworked it; this is better yes? Also added the check and disabled signup parameter! your help much appreciated!!

 var tokenDict : [String:String] = [:]

    

    func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {

        if (webView.URL?.scheme == "https" && webView.URL?.host == "www.dropbox.com" && webView.URL?.path == "/1/oauth2/redirect_receiver") {

            //print(webView.URL?.fragment)

            let tokenText = String(UTF8String: webView.URL!.fragment!)

            let parsedTokens = tokenText?.componentsSeparatedByString("&")

            //print("tokenText \(parsedTokens)")

            for token in parsedTokens! {

                let tokenP = token.componentsSeparatedByString("=")

                tokenDict[tokenP[0]] = tokenP[1]

            }

            if (tokenDict["state"] == token2Verify) {

                token2Save = tokenDict["access_token"]!

                let defaults = NSUserDefaults.standardUserDefaults()

                defaults.setObject(token2Save, forKey: "dropBoxAuth")

            }

        }

        progressView.setProgress(0.0, animated: false)

    }

 

Need more support?