Laravel 颁发多个令牌的 Passport 良好做法

Laravel Passport good practices for issuing multiple tokens

我有一个关于 Laravel Passport 以及管理 api access_tokens.

的最佳方法的问题

目前我们有:

grant_type: password发行的第一个令牌将仅用于获取个人用户信息。

这是个好习惯吗?

我们想按如下方式限制对资源的访问: 包含对其访问令牌具有特定范围的 CRUD 操作的“消息”资源。

因此我们希望每个资源都受到 不同令牌和不同范围的保护。

个人access_token是为了什么而生的?

编辑 1:

为了管理用户权限,我们使用来自 Laravel 的 Gates & Policies。

Laravel Passport 使您能够在几分钟内实现完整的 Oauth2 服务器。这意味着,您可以安装一个完整的服务器,不仅可以管理对您自己的应用程序的访问,还可以管理对第三方应用程序的访问。

当我说 "your own apps" 时,我指的是您 and/or 您的团队开发的那些。 "third-party apps" 我的意思是那些可以访问您的 API 的其他开发人员开发的那些。令牌范围是限制此第三方应用可以代表您的用户执行的操作的好方法。

以脸书为例。如果您想通过 Facebook 在您的应用程序中实施访问,您的用户将需要允许您的应用程序访问他们的个人资料数据,以便检索他们的详细信息以有效地登录您的系统。

来自Passport documentation

Token Scopes

Scopes allow your API clients to request a specific set of permissions when requesting authorization to access an account. For example, if you are building an e-commerce application, not all API consumers will need the ability to place orders. Instead, you may allow the consumers to only request authorization to access order shipment statuses. In other words, scopes allow your application's users to limit the actions a third-party application can perform on their behalf.

现在,如果您的 API 将仅由您的应用程序使用,我的意思是,如果您不打算向任何人公开或制作 public 您的 API 蓝图,但您的团队,您可以只授权具有角色和权限的用户 and/or 实施 Laravel Gates/Policies。

然后您可以通过令牌识别用户并检查用户是否有权permission/role进行特定操作或访问某些数据(或部分数据)。