customergauge / cognito
AWS Cognito provider for Laravel Authentication
Installs: 32 798
Dependents: 0
Suggesters: 0
Security: 0
Stars: 21
Watchers: 3
Forks: 7
Open Issues: 0
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 Provider 🔑
This library provides a CognitoUserProvider for Laravel.
Installation
composer require customergauge/cognito
Usage
Auth configuration
In the auth.php
file, add the following settings:
Default Guard
'defaults' => [ 'guard' => 'cognito-token', 'passwords' => 'users', ],
The new Guard configuration
'guards' => [ 'cognito-token' => [ 'driver' => 'token', 'provider' => 'cognito-provider', 'storage_key' => 'cognito_token', 'hash' => false, ], ],
The User Provider configuration
'providers' => [ 'cognito-provider' => [ 'driver' => \CustomerGauge\Cognito\CognitoUserProvider::class, ], ],
Cognito Environment Variables
/* |-------------------------------------------------------------------------- | 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'), ],
Auth Middleware
Configure the auth
middleware at App\Http\Kernel
with 'auth:cognito-token'
UserFactory
The last thing you'll need is to provide your own implementation of UserFactory
and register it in a ServiceProvider.
final class CognitoUserFactory implements UserFactory
{
public function make(array $payload): ?Authenticatable
{
return new MyUserObject(
$payload['username'],
$payload['custom:my_custom_cognito_attribute'],
);
}
}
In the provider:
$this->app->bind(CustomerGauge\Cognito\Contracts\UserFactory, App\Auth\CognitoUserFactory::class);