customergauge / cognito
AWS Cognito提供者用于Laravel身份验证
2.0.0
2024-06-12 11:31 UTC
Requires
- php: >=8.1
- ext-gmp: *
- ext-json: *
- illuminate/contracts: >=7.1
- web-token/jwt-library: ^3.0
Requires (Dev)
- doctrine/coding-standard: ^12.0
- illuminate/cache: >=7.1
- illuminate/config: >=7.1
- illuminate/container: >=7.1
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^10.0
README
Laravel Cognito提供者 🔑
此库为Laravel提供CognitoUserProvider。
安装
composer require customergauge/cognito
使用
身份验证配置
在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'
UserFactory
最后,你需要提供一个自己的UserFactory
实现并在ServiceProvider中注册它。
final class CognitoUserFactory implements UserFactory
{
public function make(array $payload): ?Authenticatable
{
return new MyUserObject(
$payload['username'],
$payload['custom:my_custom_cognito_attribute'],
);
}
}
在提供商中
$this->app->bind(CustomerGauge\Cognito\Contracts\UserFactory, App\Auth\CognitoUserFactory::class);