-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Archery Restful API #1475
Archery Restful API #1475
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1475 +/- ##
==========================================
+ Coverage 74.89% 75.43% +0.53%
==========================================
Files 83 91 +8
Lines 13432 14431 +999
==========================================
+ Hits 10060 10886 +826
- Misses 3372 3545 +173
Continue to review full report at Codecov.
|
This comment was marked as outdated.
This comment was marked as outdated.
太强了, 这是在里面实现了一个 oauth 吗? |
oauth要实现有点繁重,所以用了现成的simplejwt,不用建表 |
有没有办法直接开放所有人生成API key ? 你觉得会有这个需求吗 |
权限类IsInUserWhitelist目前是我自定义的限定白名单用户,这里如果配置成内置的rest_framework.permissions.IsAuthenticated就可以实现所有人用户授权(内置的还有AllowAny、IsAdminUser等),如果要定制权限只要稍加修改sql_api/permissions.py |
默认所有用户都可以获取token,不过只有授权的用户可以请求业务接口,当前配置是全局使用一个权限类,也可以对每个接口应用不同的权限类 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
如果archery 自己的前端想用 api 应该怎么做改造? |
用户登录archery前端时让后端生成一个token返回存储在前端,前端每次调用业务接口时把token添加到header里?或者api同时启用jwt和session认证? |
使用session鉴权post api时同样需要csrftoken,这样archery前端使用api时就不需要做额外处理,也不需要关注token的lifetime问题,内部调用api使用session,外部调用使用jwt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
方便对接其他程序,内部的系统也可以慢慢迁到api
已合并,可以更新下wiki文档 |
wiki已更新 |
API字段没有详细描述,比如errlevel有几个等级,需要我去一个一个尝试,希望文档能得到补充 |
/api/auth/token/verify/ 这个接口校验token是否有效,如果token有效返回的是一个空对象,我觉得返回一个状态码更好。基于API做处理也会更简单 |
你好, 欢迎你提出新的 issue , 本pr 已经 merge, 讨论已经结束了, 另外你所说的改进项欢迎 pr |
我需要调用API接口,请问一下这两个步骤在哪里这只我没有找到。 |
fix #354
目前支持的接口:
Restful API框架: django-rest-framework
JWT验证:djangorestframework-simplejwt
OpenAPI swagger:drf-spectacular
OpenAPI swagger-ui:
http://archeryhost:9123/api/swagger/
redoc:
http://archeryhost:9123/api/redoc/
使用:
设置token lifetime
access_token lifetime: settings.SIMPLE_JWT['ACCESS_TOKEN_LIFETIME']
refresh_token lifetime: settings.SIMPLE_JWT['REFRESH_TOKEN_LIFETIME']
配置API_USER_WHITELIST,将API账号添加至白名单
使用API账号获取token