Forum Discussion

Felipe L.3's avatar
Felipe L.3
New member | Level 1
11 years ago

Client Creation/Login - Web Browser Page/Tab Auto Close

Hi,
is it possible to the page close automatically after the user create/log into his/her account? For this step a new page/tab is open in the web browser, but it does not close automatically. I also have not found a way (using Python, JS, HTML...) to do so. All I did was put a message asking for the user to close the tab... Here's the code:

def dropboxStart(self):
    self.session = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
    self.requestToken = self.session.obtain_request_token()
    urlDropbox = self.session.build_authorize_url(self.requestToken, "http://localhost:8082/createClient/")
    webbrowser.open(urlDropbox)

def createClient(self, oauth_token, uid):
    accessToken = self.session.obtain_access_token(self.requestToken)
    self.client = DropboxClient(self.session)
    return """
        <html>
         <head>
         </head>
         <body>
         <h1>Connected to Dropbox. Please, close this tab.</h1>
         </body>
        </html>
        """

Is possible to close this new tab automatically right after the log into the Dropbox account?

Thank you!

2 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    11 years ago

    For context, is this a web app that users will be accessing over the internet? If so, you should return a redirect (instead of opening the browser on the system) to send the user to the authorize page, and use the callback to send the user back to your app, so that it all uses the same tab.

    If this is a desktop app, there isn't necessarily a good solution, unfortunately. JavaScript does have window.close but that only works for windows that were opened by script to begin with, meaning you'd need to have had another tab that opened it to in the first place. Other solutions would likely be more OS and browser specific (and unfortunately a bit outside the scope of the Dropbox API itself).

    Alternatively, you can do the app authorization flow in an embedded web view in your app, so that you have full control over it, but there are some disadvantages with that. (I.e., It offers less assurance to the user that they're actually on the Dropbox web site, the embedded browser is more likely to be out of date/unsupported, and the user is less likely to already be signed in than they are in their own browser.)

  • Felipe L.3's avatar
    Felipe L.3
    New member | Level 1
    11 years ago

    Yeah, I thought so... Anyway, thank you so much for your help!

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!