benbjurstrom/cognito-jwt-guard
Composer 安装命令:
composer require benbjurstrom/cognito-jwt-guard
包简介
A laravel auth guard for JSON Web Tokens issued by Amazon AWS Cognito
README 文档
README
Laravel authorization guard for JSON Web Tokens issued by Amazon AWS Cognito
Overview
This package provides a Laravel authentication guard to validate JSON Web Tokens (JWT) issued by the configured AWS Cognitio User Pool. The guard accepts tokens passed through the Authorization header or set as a CognitoIdentityServiceProvider cookie.
Once the token has been validated against the pool’s public key the guard will look for a Laravel user with a cognito_uuid value equal to the username property contained in the token.
If a local Laravel user is found the guard will authenticate them for the duration of the request. If one is not found and Single Sign-On is enabled this package will create a new Laravel user.
Note that this package does not provide methods for exchanging a username and password for a token. As such it is intended to be used with Laravel API-driven applications where the client would either obtain the token directly from Cognito or through a dedicated application responsible for authentication.
Installation
You can install the package using composer
composer require benbjurstrom/cognito-jwt-guard
Next publish the migration and the config/cognito.php config file with:
php artisan vendor:publish --provider="BenBjurstrom\CognitoGuard\CognitoServiceProvider"
Next go ahead and run your migrations. This will add the required cognito_uuid property to your users table
php artisan migrate
Add your AWS Cognito user pool's identifier and region to the .env file
AWS_COGNITO_REGION= AWS_COGNITO_USER_POOL_ID=
You will also need to change the auth driver in your config/auth.php file
// config/auth.php 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'cognito', // This line is important 'provider' => 'users', ], ],
Finally, depending on how you configured your Cognito User Pool's required attributes you may also want to make adjustments to your Single Sign-On settings in the published config/cognito.php file
// config/cognito.php /* |-------------------------------------------------------------------------- | Single Sign-On Settings |-------------------------------------------------------------------------- | If sso is true the cognito guard will automatically create a new user | record anytime the username attribute contained in a validated JWT | does not already exist in the users table. | | The new user will be created with the user attributes listed here | using the values stored in the given cognito user pool. Each attribute | listed here must be set as a required attribute in your cognito user | pool. | | When sso_repository_class is set this package will pass a new instance | of the the auth provider's user model to the given class's | createCognitoUser method. The users model will be hydrated with the given | sso_user_attributes before it is passed. */ 'sso' => env('SSO', false), 'sso_repository_class' => null, 'sso_user_attributes' => [ 'name', 'email', ]
Configuring an sso_repository_class is optional but doing so allows you to modify the new user record before it is saved or to dispatch events. An example sso_repository_class might look like this:
<?php namespace App\Repositories; use App\Models\User; use App\Events\UserWasRegistered; class UserRepository { public function createCognitoUser(User $user): User { $user->save(); event(new UserWasRegistered($user)); return $user; } }
Security
If you discover any security-related issues, please email ben@jelled.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
benbjurstrom/cognito-jwt-guard 适用场景与选型建议
benbjurstrom/cognito-jwt-guard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.06k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2020 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「Authentication」 「auth」 「laravel」 「jwt」 「amazon aws」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 benbjurstrom/cognito-jwt-guard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 benbjurstrom/cognito-jwt-guard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 benbjurstrom/cognito-jwt-guard 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Multiauth package
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 13.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-20