python - Django OAuth2 invalid grant_type -
i using django oauth toolkit , create sign_up call - in return gives me response:
{ "username": "boban16", "client_id": "sxfb8wod5qupdyp5c4pjjhxaqqfpvcw7fka3sumy", "client_secret": "3nurebdpx9ccseevyohpxz76om0keoxfwk2rrqjnk5wvyua1tuf37sh0of473wcgej3tcmfln9kpnp9vkgepwxrarc6iimqi6y34pyvu7otlcxhjs2ssomsp2c0xnxra" }
so, trying make call generate token using postman application - request looks this:
and response:
{ "error_description": "invalid credentials given.", "error": "invalid_grant" }
this code urls.py
urlpatterns = patterns('', url(r'^sign_up/$', signup.as_view(), name="sign_up"), url(r'^login/$', login.as_view(), name="login"), url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), )
this part settings.py
rest_framework = { 'default_authentication_classes': ( # 'rest_framework.authentication.basicauthentication', 'oauth2_provider.ext.rest_framework.oauth2authentication', ), 'default_permission_classes': ( 'rest_framework.permissions.allowany', ), }
i not sure problem , how can fix it. has advice how make work? lot!
------- update --------
i got response:
curl -v http://127.0.0.1:8000/o/token/ -x post -u "<client_id>:<client_secret>" -d "grant_type=client_credentials"
and response:
* hostname not found in dns cache * trying 127.0.0.1... * connected 127.0.0.1 (127.0.0.1) port 8000 (#0) * server auth using basic user 'jnbudguj44ndu49yeokhxu0zunfibpdesc8pvtqu' > post /o/token/ http/1.1 > authorization: basic sk5cvwrnvuo0ng5kdtq5ewvva0h4vtbavu5mswjwzevtqzhqvlrrvtpaqvnwz0xly3didxa2ajj2yljqakc1wlfzenpwwfzwqu5hchj0wwzvnniya2vpukezzw9vnlh5m0tsmenkogpwn3flt2xftenothztuk5vtzbkue5yngdorxdvrnb4udnkbhdxy0fqrkpiv0rmskjzynpmnjj5de5daefvm29rca== > user-agent: curl/7.37.1 > host: 127.0.0.1:8000 > accept: */* > content-length: 29 > content-type: application/x-www-form-urlencoded > * upload sent off: 29 out of 29 bytes * http 1.0, assume close after body < http/1.0 401 unauthorized < date: sat, 13 jun 2015 16:14:19 gmt < server: wsgiserver/0.2 cpython/3.4.3 < content-type: application/json < cache-control: no-store < pragma: no-cache < x-frame-options: sameorigin < * closing connection 0 {"error": "unauthorized_client"}
as can see in response - got authorization token, says @ end - unauthorized client. okay or not? thanks!
i figured out problem.
there issue in post_save signal creating applications automatically.
def create_auth_client(sender, instance=none, created=false, **kwargs): """ intended used receiver function `post_save` signal on custom user model creates client_id , client_secret authenticated users """ if created: application.objects.create(user=instance, client_type=application.client_confidential, authorization_grant_type=application.grant_client_credentials) # todo post_save.connect(create_auth_client, sender=user)
this correct solution. can use these calls sign_up / getting oauth2 token:
curl -x post -f "username=test1" -f "password=test1" http://127.0.0.1:8000/sign_up/ curl -x post -d "grant_type=client_credentials" -u "<client_id>:<client_secret>" http://127.0.0.1:8000/o/token/
Comments
Post a Comment