Greetings everyone!
I’ve followed the instructions on the laravel-auth0 Github page to use Eloquent models for Auth0 integration on my Laravel app and everything works well but I’m unable to access custom claims after implementing the custom UserRepository.php. The only Auth0 specific token that I seem to be able to access is “auth0_id”. I’ve been banging my head on this problem for over a week and I’m about ready to give up on Auth0 for my app. I’ve tried namespace and non namespace claims. Here is a short snippet of my UserRepository.php file.
I can’t even seem to access more common claims like “sub” in this configuration. Please help me see what I’m missing here.
<?php declare(strict_types=1); namespace App\Repositories; use App\Models\{User, Team}; // Ensure you import the Team model use Auth0\Laravel\{UserRepositoryAbstract, UserRepositoryContract}; use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Support\Facades\{Cache, Config, Hash}; use Illuminate\Support\Str; use Illuminate\Support\Facades\Log; final class UserRepository extends UserRepositoryAbstract implements UserRepositoryContract { public function fromAccessToken(array $user): ?Authenticatable { $identifier = $user['sub'] ?? $user['auth0_id'] ?? null; if (null === $identifier) { return null; } return User::where('auth0_id', $identifier)->first(); } public function fromSession(array $auth0User): ?Authenticatable { // Determine the Auth0 identifier for the user from the $auth0User array. $identifier = $auth0User['sub'] ?? $auth0User['auth0_id'] ?? null; // Collect relevant user profile information from the $auth0User array for use later. $profile = [ 'auth0_id' => $identifier, 'name' => $auth0User['name'] ?? 'Unknown User', 'email' => $auth0User['email'] ?? 'noemail@example.com', 'xyz_roles => $auth0User['xyz_roles'] ?? 'null', ]; }