PHP code example of benbjurstrom / cognito-jwt-guard
1. Go to this page and download the library: Download benbjurstrom/cognito-jwt-guard library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
benbjurstrom / cognito-jwt-guard example snippets
// config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'cognito', // This line is important
'provider' => 'users',
],
],
// 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
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;
}
}