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

InvalidClientIdError in fetch_token()

Open kination opened this issue 6 years ago • 5 comments

Hello, I faced an error when go on fetch_token() with received url with code and state:

127.0.0.1 - - [15/Jan/2019 16:41:02] "GET /oauth2?code=SOME-CODE-DATA&state=SOME-STATE-DATA HTTP/1.1" 500 -
Traceback (most recent call last):
...
...
oauthlib.oauth2.rfc6749.errors.InvalidClientIdError: (invalid_request) The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed

Is this known issue? Seems something is being fixed in fetch_token in #331 . If this is not fixed, is there a workaround?

Thanks.

kination avatar Jan 15 '19 07:01 kination

@djKooks Can you please provide a reproducible test case?

singingwolfboy avatar Jan 15 '19 17:01 singingwolfboy

@singingwolfboy thanks. I'm working on flask app, and auth server is custom one(implemented in golang):

...
app = Flask(__name__)

@app.route('/')
def main():
	scopes = ['all']
	auth_session = OAuth2Session(CLIENT_ID, redirect_uri=REDIRECT_URL)
	authorization_url, state = auth_session.authorization_url(AUTH_SERVER_AUTHORIZE)
	session['oauth_state'] = state
	return redirect(authorization_url)
	
@app.route('/oauth2')
def callback():
	auth_session = OAuth2Session(CLIENT_ID, state=session['oauth_state'])
	token = auth_session.fetch_token(AUTH_SERVER_TOKEN,
							client_secret=CLIENT_SECRET,
							authorization_response=request.url
	)
...

Callback come with code and state, like http://localhost:5555/oauth2?code=PQ9DKLB1MSIYUVMGC2HXWG&state=b0rDHjr9XOwUFw44af2gSGG8aBiTDe. Error above comes on auth_session.fetch_token().

Could you find something?

kination avatar Jan 16 '19 02:01 kination

@djKooks Try passing in include_client_id = True to your auth_session.fetch_token() call. I was having a similair issue arise after updating from 1.1.0 and 1.2.0 because this newly added parameter and passing that in fixed it (although mine was an InvalidClientError)

holsaeter avatar Feb 06 '19 15:02 holsaeter

@holsaeter I can confirm that that worked in my case, thanks. (LegacyApplicationClient fetching a token from Microsoft Azure)

@singingwolfboy, do you know whether something needs to be done to force an update on readthedocs.io? https://requests-oauthlib.readthedocs.io/en/latest/api.html doesn't reflect the current state of the project and omits the include_client_id parameter to fetch_token(). That parameter is documented in the commit that added it, though, so it appears that Read the Docs is behind.

dmcgee avatar Oct 31 '19 22:10 dmcgee

@singingwolfboy Sorry to be bringing this old stuff back to life. Found some free time and wanted to cherry pick a few of these issues to clean up. Seems to me that this issue is settled, however, ReadTheDocs is in fact behind. Pulled down the repo, ran make html in docs, thinking that would update the html files, then I noticed that these are ignored files? .gitignore line 9. Anyways I figured you might know how to refresh/rebuild the docs.

[EDIT]

Continued reading and found this issue addressing a similar out of sync docs issue: #392 Read the Docs is out of sync. and it looks like that the project needs push out a release to rebuild the documentation. Is there any desire to push a general release update just to get the project on level footing again? If anything get the documentation more current?

jtroussard avatar Jul 21 '20 21:07 jtroussard