We’ve udated Laravel version from 9 to 10 and auth0/login version from 7.4 to 7.12. We did all configuration changes according to the documentation and login to our application works. But our feature tests stopped working. We have always used actingAs to authorize the user, here is an example:
$this->actingAs($user, 'auth0');
'guards' => [
'auth0' => [
'driver' => 'auth0.authorizer',
'provider' => 'auth0',
'configuration' => 'api',
],
],
But now all tests requests return 401.
Here: https://github.com/auth0/laravel-auth0/blob/main/tests/Unit/Traits/ImpersonateTest.php
I found that we can use ‘Impersonate’ but seems like it’s already deprecated.
I’ve tried to use:
$this->actingAsAuth0User
and $this->impersonate()
But $request->user()
returns Auth0\Laravel\Users\StatelessUser
or Auth0\Laravel\Users\ImposterUser
instead of App\Models\User
. So application crashes with a lot of bugs.
Found a temporary solution:
$imposter = CredentialEn■■■y::create(
user: new ImposterUser(['sub' => uniqid(), 'email' => $user->email]),
accessTokenExpiration: time() + 3600
);
$imposter->setUser($user);
$this->impersonateToken($imposter)->json.....
Temporary because CredentialEn■■■y is deprecated.