API design: Auth0 用于身份验证和内部授权

API design: Auth0 for authentication and internal authorization

我正在创建一个 iOS 与 Flask API 对话的本机应用程序。

我的计划是让 iOS 前端句柄使用 Auth0 锁登录。之后,前端会将 JWT 存储在本地内存中,并在每个 API 请求中使用它。

在后端,我计划让用户 table 具有内部 ID 字段和 Auth0 ID 字段。根据 API 请求,我会通过 Auth0 ID 查找用户,然后使用像 flask-bouncer 这样的库来处理资源授权。

  1. 这是一种有效的方法吗?
  2. Auth0 是否有开箱即用的功能 我正在重建?如果是这样,使用的优点是什么 Auth0 版本?
  3. 是否有任何我遗漏的未来影响 用这种方法?
  4. 使用 Auth0 而不是按照 this 之类的方式自己构建它有什么优势?
  5. 还有什么要考虑的吗?

Is this a valid approach?

取决于你所说的有效。但它会起作用,是的。

Are there any out of box features of Auth0 that I am rebuilding? If so what are the advantages of using the Auth0 version?

您没有使用范围授权。参见 Auth0's tutorial for Flask

Are there any future implications that I am missing with this approach?

这是一个广泛的问题,我不知道答案。

What are the advantages of using Auth0 instead of building it myself following something like this?

您不必担心注册、登录、验证电子邮件、暴力破解保护、重置密码、MFA 等。所有这些都是开箱即用的。但是...一些更复杂的事情可能需要您付出额外的努力。

Anything else to consider?

明确决定将哪些信息存储在何处以及是否要将用户存储在数据库中。一个容易犯的错误是 Auth0 和您的数据库中的某些数据有多个真实来源(例如名字和姓氏)。另见 User Data Storage Best Practices.