Akash Aage
Akash Aage

Reputation: 21

getting error {"error": "invalid_client"} when creating access token in django

I have created Application in my project and its successfully created. and I received Client ID and Client secret from this. but when I am entering command to get access token this gives me an error message

{"error": "invalid_client"}

I entered this command curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" -u"<client_id>:<client_secret>" http://<ip_address>:<port>/o/token/ In Windows CMD using my username password.

I have added this in settings.py

'oauth2_provider' in INSTALLED_APPS

OAUTH2_PROVIDER = {
    # this is the list of available scopes
    'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'}
}

REST_FRAMEWORK = {
    'DEFAULT_FILTER_BACKENDS' : [ 'django_filters.rest_framework.DjangoFilterBackend' ],
    'DEFAULT_AUTHENTICATION_CLASSES' : ('oauth2_provider.contrib.rest_framework.OAuth2Authentication',),
}

But still getting {"error": "invalid_client"} In CMD.

Unauthorized: /o/token/
[31/May/2022 18:08:17] "POST /o/token/ HTTP/1.1" 401 27

and above error in VS code's Terminal.

How I get solution of it.

Upvotes: 2

Views: 1498

Answers (1)

pelusa
pelusa

Reputation: 61

You tried to request a token with client_secret generated by django oauth toolkit admin (hashed value). You must copy the client_secret before saving. This change was implemented on 2022-04-24

According to the changelog:

#1093 (Breaking) Changed to implement hashed client_secret values. This is a breaking change that will migrate all your existing cleartext application.client_secret values to be hashed with Django’s default password hashing algorithm and can not be reversed. When adding or modifying an Application in the Admin console, you must copy the auto-generated or manually-entered client_secret before hitting Save.

You can read more about this here

Upvotes: 4

Related Questions