使用 Azure AD 保护 python 休息 API

Secure python rest API with azure AD

我有一些 python 休息 API 我想用 azure AD 来保护。 为此,我正在考虑根据示例验证每个请求的承载令牌: https://github.com/Azure-Samples/ms-identity-python-webapi-azurefunctions.

这是正确的做法吗?最佳做法是什么? 没有更简单的方法来管理会话?类似于 flask-login 但用于 APIs 的东西(即不基于会话 cookie 的东西)?

谢谢 里卡多

Is that the correct approach? What is the best practice?

是的,是正确的,应该是最好的实践(至少我能找到)。要使用 Azure AD 保护 APIs,您始终需要为其注册一个 AD 应用程序,公开 APIs,然后在您的客户端应用程序中添加 API 权限,用户登录并同意权限,获取令牌并调用 API.

There is not a simpler way to managing sessions? Something similar to flask-login but for APIs (i.e. something not based on session cookies)?

据我所知,APIs 没有类似于 flask-login 的东西。