Microsoft Service Api returning invalid grant using oauth2 protocol,using flask application?

779 views Asked by At

I am trying to make an sso using Flask and using library flask_oauthlib

while on selecting the microsoft user to login and clicking multiple times on login results to give me 401 invalid grant error, error like this:

office_sso OAuthException: type: 'invalid_response' data: '{u'timestamp': u'2017-09-01 18:43:19Z', u'trace_id': u'66cd14ce-598a-44f5-8af5-105c2d350a00', u'correlation_id': u'1e3cbfb9-517e-4074-ba7c-e5cd399e26d0', u'error_description': u"AADSTS70002: Error validating credentials. AADSTS70000: 'redirect_uri' must be provided when presenting an authorization code requested with a 'redirect_uri'.\r\nTrace ID: 66cd14ce-598a-44f5-8af5-105c2d350a00\r\nCorrelation ID: 1e3cbfb9-517e-4074-ba7c-e5cd399e26d0\r\nTimestamp: 2017-09-01 18:43:19Z", u'error': u'invalid_grant', u'error_codes': [70002, 70000]}'.

Any help

1

There are 1 answers

0
lod On

You need to provide a redirect_uri parameter in the redirect request, this must match the one configured server side.

I suspect your problem arose trying to translate the Github example, oauth typically requires the request_uri parameter but the Github implementation does not.

Edit the example to include the parameter like this:

oauth = OAuth2Session(client_id, redirect_uri=redirect_uri, scope=scope)
url, state = oauth.authorization_url(authorization_base_url)
resp = make_response(redirect(url))