Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cgauge/laravel-cognito-provider
AWS Cognito provider for Laravel Authentication
https://github.com/cgauge/laravel-cognito-provider
Last synced: 16 days ago
JSON representation
AWS Cognito provider for Laravel Authentication
- Host: GitHub
- URL: https://github.com/cgauge/laravel-cognito-provider
- Owner: cgauge
- License: mit
- Created: 2020-03-15T17:08:54.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-12T11:32:14.000Z (7 months ago)
- Last Synced: 2024-12-06T13:36:44.391Z (28 days ago)
- Language: PHP
- Size: 32.2 KB
- Stars: 21
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
![Build](https://github.com/cgauge/laravel-cognito-provider/workflows/Tests/badge.svg)
[![Code Coverage](https://scrutinizer-ci.com/g/cgauge/laravel-cognito-provider/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/cgauge/laravel-cognito-provider/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/cgauge/laravel-cognito-provider/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/cgauge/laravel-cognito-provider/?branch=master)# Laravel Cognito Provider 🔑
This library provides a CognitoUserProvider for Laravel.
# Installation
```bash
composer require customergauge/cognito
```# Usage
### Auth configuration
In the `auth.php` file, add the following settings:
Default Guard
```php
'defaults' => [
'guard' => 'cognito-token',
'passwords' => 'users',
],
```The new Guard configuration
```php
'guards' => [
'cognito-token' => [
'driver' => 'token',
'provider' => 'cognito-provider',
'storage_key' => 'cognito_token',
'hash' => false,
],
],
```The User Provider configuration
```php'providers' => [
'cognito-provider' => [
'driver' => \CustomerGauge\Cognito\CognitoUserProvider::class,
],
],
```Cognito Environment Variables
```php
/*
|--------------------------------------------------------------------------
| 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);
```