使用OAuth2保护Flask-Restful API

Ale*_*Ale 8 oauth oauth-2.0 flask-restful

好的,所以我使用Flask-Restful编写了一个API,现在我想实现OAuth2授权.

我已经尝试了pyoauth2,但它没有文档,教程非常复杂.

所以,我的问题是:我该怎么做?

sam*_*sam 5

  1. 按照flask-oauthlib指南进行基本端点设置.确保它适用于vanilla flask端点.

  2. 配置您的API以使用oauth装饰器.

    oauth = OAuth2Provider(app)
    api = restful.Api(app, decorators=[oauth.require_oauth('email')])
    
    Run Code Online (Sandbox Code Playgroud)