I'm trying to send a request with django to get an access_token from my api using OAuth2. I'm executing this code :
data = {'username': 'admin', 'password': '123123', 'grant_type':
'password','client_id': 'xxx','client_secret': 'xxx'}
headers = {'content-type': 'application/x-www-form-urlencoded'}
r = requests.post(url, data=data, headers=headers)
When I send this request I get this error :
{'error': 'unsupported_grant_type'}
Thanks for your help !
If anyone is interested the correct request was :
payload = "grant_type=password&client_secret=xxx&client_id=xxx&username=username&password=password"
headers = {
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache",
}
response = requests.request("POST", url, data=payload, headers=headers)
If you don't want to encode data in url, you can put this in your settings.
OAUTH2_PROVIDER = {
'OAUTH2_BACKEND_CLASS': 'oauth2_provider.oauth2_backends.JSONOAuthLibCore',
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With