graphene-ict/laravel-cognito-guard

Laravel 验证 AWS Cognito 用户池发布的 JSON Web Tokens (JWT) 的身份验证保护器


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Laravel 验证 AWS Cognito 用户池发布的 JSON Web Tokens (JWT) 的身份验证保护器

安装

您可以通过 composer 安装此包

composer require graphene-ict/laravel-cognito-guard

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="GrapheneICT\CognitoGuard\Services\CognitoAuthServiceProvider" --tag="config"

这是已发布配置文件的内容

return [
    /*
     * If persist_user_data is true the cognito guard will automatically create a new user
     * record anytime the user contained in a validated JWT
     * does not already exist in the users table.
     *
     * The new user will be created with the user attributes name, email, provider and provider_id so
     * it is required for you to add them at the list of fillable attributes in the model array, if you
     * wish to add more attributes from the cognito modify before it is saved or use the events.
     *
     */
    'persist_user_data' => true,

    'models' => [
        /*
         * When using this package, we need to know which
         * Eloquent model should be used for your user. Of course, it
         * is often just the "User" model but you may use whatever you like.
         *
         */
        'user' => [
            'model' => App\Models\User::class,
        ],
    ],
];

由于 persist_user_data 默认为 true,用户将自动保存以下属性:name, email, provider 和 provider_id,因此必须在可填充列表中添加它们。如果您想使用 CognitoService 类扩展更多属性,请在保存之前修改数据或使用事件。

   $cognitoService = new CognitoService();
   $attributes = $cognitoService->getCognitoUserAttributes($token);

使用方法

在配置auth中使用 coginto 驱动器创建额外的保护器

   'api' => [
            'driver' => 'cognito',
            'provider' => 'users',
        ],

之后,只需将其应用于以下所示的认证默认值作为认证选项

    'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],

更新日志

请参阅 CHANGELOG 了解最近更改的详细信息。

贡献

有关详细信息,请参阅 CONTRIBUTING

安全漏洞

请查阅 我们的安全策略 了解如何报告安全漏洞。

鸣谢

许可

MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。