由 Christian Braybrooke 开发的包

v0.0.6 2024-05-06 08:35 UTC

This package is auto-updated.

Last update: 2024-09-06 09:22:50 UTC


README

用于与使用 Laravel Passport 的身份验证服务器配合使用。此包将读取传入的 JWT 并进行用户认证。

安装

composer require chrisbraybrooke/jwt

设置

  1. ChrisBraybrooke\JWT\Traits\AuthenticatesWithAuthServer 特性添加到您的 User 模型中,这包含一些帮助创建新用户的方法。

  2. 在您的 .env 文件中添加一个 OAUTH_AUTH_SERVER_API_ENDPOINT 条目,这是您的身份验证服务器的 base api url,将在创建新用户时用于获取用户信息。您还需要一个 OAUTH_PUBLIC_KEY 条目,这是在身份验证服务器上使用的公钥,允许我们验证传入的 JWT。

  3. 最后,您需要更改 config/auth.php 文件中的 api 守卫驱动程序 - 请参见下面的示例。

'api' => [
    'driver' => 'jwt', // --> We have created a driver called jwt, make sure your driver is set to this.
    'provider' => 'users',
    'hash' => false,
]

配置

您可以通过运行 php artisan vendor:publish --tag=jwt-config 来发布配置文件。