Getting Authentication Token Back in Python using QWebView?

Hello, I’m writing an application that requires an auth token in Python and I’m using QWebView to display the token url where the user can login and authorize. However, I’m using http://localhost and I’m not sure how to get the token back. The authentication page displays and the user can login but if the app is already registered, then clicking login does nothing. If the app is not registered yet, clicking login will lead them to the authorize page and when authorize is clicked, nothing happens.

When you registered your app you had to specify a redirect URI. That is where you need to capture the access token and transition users to your app:

https:// [your registered redirect URI]/#access_token=[an access token]&scope=[authorized scopes]

For my redirect URI, I just did http://localhost since I don’t have a website for my desktop app. When I go to my application’s authorization link on my browser, sign in and authorize, the link in the address bar changes to:


and I can see that the token is there. However for QWebView I’m not sure how or where I would get the token

Does QWebView allow you to fetch the current url? If so, you should read out the url, then urlparse it, extract the fragment, and parse it.

In python this would look like:

import urlparse

url = web_view.URL()
hash = url.fragment()
data = urlparse.parse_qs(hash)
access_token = data["access_token"]

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.