【发布时间】:2016-01-27 13:02:36
【问题描述】:
我正在尝试找出从我的移动应用程序到我的 api 交互的最佳流程。
我正在使用这些包:
https://github.com/evonove/django-oauth-toolkit
http://www.django-rest-framework.org
我想要这个流程:
- 用户使用用户名和密码在我的移动应用上编译注册视图
- 用户提交注册
- 我的应用程序向我的后端发出请求以获取 应用程序的令牌
- 带有令牌的应用程序调用用户注册api
- 我的后端注册用户,登录并返回用户令牌以供将来调用。
我的流程正确吗?
如果我使用基于密码的资源所有者并且我提出这样的请求:
curl -X POST -d "grant_type=password&username=username&password=password" -u "client_id:client_secret" http://127.0.0.1:8000/api/v2/oauth/token/
我明白了:
{"access_token": "09Vf0HD5nCPSEvLAnjxrghZPHfvE4c", "token_type": "Bearer", "expires_in": 36000, "refresh_token":"yDmovryDlGhkLVV6T2rTgFQxnNtguq", "scope": "read write groups"}
但如果我想通过以下方式为我的应用获取访问令牌:
curl -X POST -d "grant_type=client_credentials" -u "client_id:client_secret" http://127.0.0.1:8000/api/v2/oauth/token/
我明白了:
{"error": "unauthorized_client"}
所以我的疑问是:
我应该如何设置我的应用程序?
我的 oAuth2 应用程序应该具有哪种授权授权类型?
【问题讨论】: