Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Invalid_grant when using onedrive python sdk code flow oathuv2 #97

Closed
app5000 opened this issue Feb 13, 2017 · 7 comments
Closed

Invalid_grant when using onedrive python sdk code flow oathuv2 #97

app5000 opened this issue Feb 13, 2017 · 7 comments

Comments

@app5000
Copy link

app5000 commented Feb 13, 2017

I am using the following code to get an access_token:

import onedrivesdk

redirect_uri = 'http://localhost:5000/onedriveauth' 
client_secret = ’secret’   #secret is the string I got from onedrive app registration
client_id= ‘id’   #id is the string I got from onedrive app registration
api_base_url='https://api.onedrive.com/v1.0/'
scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']

http_provider = onedrivesdk.HttpProvider()
auth_provider = onedrivesdk.AuthProvider(
    http_provider=http_provider,
    client_id=client_id,
    scopes=scopes)

client = onedrivesdk.OneDriveClient(api_base_url, auth_provider, http_provider)
auth_url = client.auth_provider.get_auth_url(redirect_uri)

print('Paste this URL into your browser, approve the app\'s access.')
print('Copy everything in the address bar after "code=", and paste it below.')
print(auth_url)
code = raw_input('Paste code here: ')

access_token=client.auth_provider.authenticate(code, redirect_uri, client_secret) 

But I keep getting invalid_grant error on line: access_token=client.auth_provider.authenticate(code, redirect_uri, client_secret)

I don't know what is going on in the background and thus can not debug it. Can anyone help? Thanks.

Here is the error msg:

ERROR in app: Exception on /onedriveauth/ [POST]
Traceback (most recent call last):
File "/Users/Applications/User/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/Users/Applications/User/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/Applications/User/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/Applications/User/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/Applications/User/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functionsrule.endpoint
File "/Users/Documents/flaskr/myapplication.py", line 69, in decorated_function
return f(*args, **kwargs)
File "/Users/Documents/flaskr/myapplication.py", line 3791, in onedriveauth
access_token=client.auth_provider.authenticate(code, redirect_uri, client_secret)#added grant_type='authorization_code'
File "/Users/Applications/User/lib/python2.7/site-packages/onedrivesdk/auth_provider.py", line 203, in authenticate
data=params)
File "/Users/Applications/User/lib/python2.7/site-packages/onedrivesdk/http_provider.py", line 71, in send
custom_response = HttpResponse(response.status_code, response.headers, response.text)
File "/Users/Applications/User/lib/python2.7/site-packages/onedrivesdk/http_response.py", line 61, in init
raise Exception(str(message["error"]))
Exception: invalid_grant

@patrislav1
Copy link

I have the same issue.

@rushid93
Copy link

I also have the same issue.

@hanahana1618
Copy link

Try specifying the same redirect_uri in the app registration as in the code. In my case, I used http://localhost:8080/
screenshot-2018-2-24 test-onedrive registration

@app5000
Copy link
Author

app5000 commented Feb 25, 2018 via email

@tigercosmos
Copy link

I have this error since I call authenticate twice, and the code is only valid for once.

@app5000
Copy link
Author

app5000 commented Jul 12, 2018 via email

@baywet
Copy link
Member

baywet commented Oct 2, 2024

Thank you for reaching out and for your patience. This SDK is being officially deprecated. See #209 for more information

@baywet baywet closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants