Is AWS Cognito session based?
Custom Auth Provider not keeping session
I have created a custom auth provider to allow authentication through AWS Cognito. I can see that retrieveByCredentials method in my user provider is properly authenticating the user. And, I can see that the call to Auth::attempt() is true. If immediately after calling Auth::attempt() I dump the auth'd user with dd(auth()->user()) I do see the info for the user that was just authenticated.
The problem I'm facing is that after the authentication when the user is redirected to the defined "home" route, they no longer look to be logged in. If I dig down in the Laravel's Authenticate middleware and look at the authenticate method, as it's iterating through the $guards, I can see that $this->auth->guard($guard)->check() returns false.
Here is my setup:
// My custom Auth Provider
Auth::provider('cognito', function($app, array $config) {
return new CognitoUserProvider(new CognitoIdentityProviderClient([
'version' => 'latest',
'region' => 'us-west-2',
'credentials' => [
'key' => config('...'),
'secret' => config('...'),
],
]));
});
// config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'cognito' => [
'driver' => 'session',
'provider' => 'cognito',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'cognito' => [
'driver' => 'cognito',
],
]
I have also attempted to use a custom guard to no avail.
I have not made any modifications to how my session is set up in config/session.php and I have confirmed that I can define a session var and retrieve it after a redirect so my session persistence seems OK.
Any ideas why my authenticated session isn't sticking?
Please or to participate in this conversation.