V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
aidchow
V2EX  ›  Python

关于像各种 api store 里需要一个 key 才能对 api 进行访问是如何实现的?

  •  
  •   aidchow · 2017-01-03 08:25:31 +08:00 via Android · 3076 次点击
    这是一个创建于 2669 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Flask 新人一枚,之前一直在学习 android ,然后就看到所有的 api store 当要用他们提供的 api 的时候都要求带一个 kei 进行访问,而且还有请求次数,想知道要怎么实现,或者是怎么个流程,希望大大们告知一下,谢谢
    7 条回复    2017-01-04 23:48:36 +08:00
    ss098
        1
    ss098  
       2017-01-03 08:37:00 +08:00 via Android
    1. 生成指定 api 可用的 key ,并设置可用次数
    2. 收到请求时检查 key 是否可用,次数是否足够
    P0P
        2
    P0P  
       2017-01-03 09:13:26 +08:00
    有很多 api gateway 的工具可以使用,后台自己的 api 不需要加认证鉴权 cache 等功能,依赖工具封装,也可以做 api 调用频次限制能功能。例如 amazon api gateway 或者 Kong https://getkong.org/
    firstway
        3
    firstway  
       2017-01-03 09:25:43 +08:00
    OAuth 2.0
    fhefh
        4
    fhefh  
       2017-01-03 09:43:48 +08:00
    @P0P Kong 这个很棒 nice
    aidchow
        5
    aidchow  
    OP
       2017-01-03 09:51:21 +08:00 via Android
    @firstway
    @ss098
    @P0P
    感谢大家提供的思路和解决办法,我这里看了下 Kong 和我的需求很吻合
    lslqtz
        6
    lslqtz  
       2017-01-03 16:53:51 +08:00 via iPhone
    @ss098 似乎并不是指定 api 而是用户全局 api
    honmaple
        7
    honmaple  
       2017-01-04 23:48:36 +08:00
    这就是一个验证用的 token 啊,flask 的话放在 before_request 里,每次请求验证 token,一般情况下一个 token 代表的就是一个用户,可以根据 token 获取对应的用户信息,验证失败则 api 不能访问
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1124 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 18:55 · PVG 02:55 · LAX 11:55 · JFK 14:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.