requests-oauthlib icon indicating copy to clipboard operation
requests-oauthlib copied to clipboard

support for urn:ietf:wg:oauth:2.0:oob ?

Open glyph opened this issue 7 years ago • 6 comments

I'm not sure which project this belongs in a request on, but:

urn:ietf:wg:oauth:2.0:oob is a special redirect URL that indicates to some providers (google in particular) that the token code should be presented to the user so that it can be copied and pasted into (e.g.) a command-line tool.

It doesn't seem like there's anywhere to put this token value once copied.

glyph avatar May 12 '17 19:05 glyph

Hrm. Is that a bearer token of some form, or does it get converted into one in some part of an oauth dance? Do you have a specification for how this should work?

Lukasa avatar May 12 '17 20:05 Lukasa

The value in the title of the ticket here is the redirect URL.

This may mainly be a documentation issue; I eventually figured out that the thing to do when using this flow (the "other" application flow in Google's terminology) was instead of specifying oauth.fetch_token(token_url, authorization_response=authorization_response, ...), to do oauth.fetch_token(token_url, code=paste_here).

glyph avatar May 12 '17 22:05 glyph

Oh, yes, that's definitely a documentation issue. =(

Lukasa avatar May 13 '17 14:05 Lukasa

On the other hand, I'd argue that all of OAuth has a documentation issue.

Lukasa avatar May 13 '17 14:05 Lukasa

@glyph You can also do it like this, I have not used it with gmail but I it is much better then pasting the ?code={somecode} into your actual python code.

import webbrowser
from requests_oauthlib import OAuth2Session

url = "example.com/api"
redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
oauth = OAuth2Session(client_id, redirect_uri=redirect_uri)
authorization_url, state = oauth.authorization_url(url + "/login/oauth2/auth")

webbrowser.open(authorization_url)
authorization_response = input('Enter the full callback URL:  ')

token = oauth.fetch_token(url + "/login/oauth2/token", 
		authorization_response=authorization_response, client_secret=client_secret)

sigurdurb avatar Aug 04 '17 20:08 sigurdurb

@sigurdurb I tried your method, gives me an exception like oauthlib.oauth2.rfc6749.errors.MismatchingStateError: (mismatching_state) CSRF Warning! State not equal in request and response.
Can you help?

tejasa97 avatar Aug 14 '19 17:08 tejasa97