goms/cognito

AWS Cognito 提供商用于 Laravel 认证

1.0.0 2020-07-21 12:47 UTC

This package is auto-updated.

Last update: 2024-09-21 22:20:13 UTC


README

Build Code Coverage Scrutinizer Code Quality

Laravel Cognito 提供商 🔑

这个库为 Laravel 提供了 CognitoUserProvider。

安装

composer require customergauge/laravel-cognito-provider

用法

认证配置

auth.php 文件中,添加以下设置

默认守卫

    'defaults' => [
        'guard' => 'cognito-token',
        'passwords' => 'users',
    ],

新的守卫配置

    'guards' => [
        'cognito-token' => [
            'driver' => 'token',
            'provider' => 'cognito-provider',
            'storage_key' => 'cognito_token',
            'hash' => false,
        ],
    ],

用户提供者配置

    'providers' => [
        'cognito-provider' => [
            'driver' => \CustomerGauge\Cognito\CognitoUserProvider::class,
        ],
    ],

Cognito 环境变量

    /*
    |--------------------------------------------------------------------------
    | Cognito Custom Configuration
    |--------------------------------------------------------------------------
    |
    | The following configuration is not part of standard Laravel application.
    | We use it to configure the CognitoUserProvider process so that we can
    | properly validate the JWT token provided by AWS Cognito.
    |
    */

    'cognito' => [
        'pool' => env('AWS_COGNITO_USER_POOL_ID'),
        'region' => env('AWS_COGNITO_USER_POOL_REGION'),
    ],

认证中间件

App\Http\Kernel 中配置 auth 中间件为 'auth:cognito-token'