小编Aki*_*ila的帖子

django-oauth-toolkit:自定义身份验证响应

我是Django OAuth Toolkit的新手。我想自定义身份验证响应。

我在Django应用程序上的身份验证URL配置是:

url('authenticate/',
    include('oauth2_provider.urls', namespace='oauth2_provider'))
Run Code Online (Sandbox Code Playgroud)

https://django-oauth-toolkit.readthedocs.io/zh-CN/latest/install.html

现在,当我启动此命令时:

curl -X POST -d 'grant_type=password&username=$username&password=$password'
 -u "$client_id:$client_secret" http://127.0.0.1:8000/authenticate/token/
Run Code Online (Sandbox Code Playgroud)

我得到这个回应:

{
   "access_token": "ATiM10L0LNaldJPk12drXCjbhoeDR8",
   "expires_in": 36000,
   "refresh_token": "II4UBhXhpVDEKWmsUQxDzkj3OMjW1p",
   "scope": "read groups write",
   "token_type": "Bearer"
}
Run Code Online (Sandbox Code Playgroud)

并希望此响应:

{
   "access_token": "ATiM10L0LNaldJPk12drXCjbhoeDR8",
   "expires_in": 36000,
   "refresh_token": "II4UBhXhpVDEKWmsUQxDzkj3OMjW1p",
   "scope": "read groups write",
   "token_type": "Bearer",
   "member": {
      "id": 1,
      "username": "username",
      "email": "email@gmail.com",
      ....
   }
}
Run Code Online (Sandbox Code Playgroud)

我只想覆盖此响应,以添加已认证用户的信息。我已经阅读了django-oauth-toolkit的文档。而且我没有找到解决问题的办法...

python django python-3.x django-rest-framework django-oauth

1
推荐指数
1
解决办法
477
查看次数