I have a stub AdminUserProvider implementation that just does logging. It wasn’t used in our Laravel 8 Auth0 integration.
It looks like it is not being called by Auth0 in this configuration which leaves me wondering how we can customise user provider which is important to our need for two distinct authentication paths (which start with Auth0 authentication).
namespace App\Auth;
use App\Models\Admin;
use App\Models\User;
use Illuminate\Contracts\Auth\Authenticatable;
class CustomUserRepository implements \Auth0\Laravel\Contract\Auth\User\Repository
{
/**
* Generate a \Auth0\Laravel\Model\Stateful\User instance from an available Auth0-PHP user session.
*
* @param array $user an array containing the raw Auth0 user data
*/
public function fromSession(array $user): ?Authenticatable {
return Admin::whereEmail($user['email'])->first();
}
/**
* Generate a \Auth0\Laravel\Model\Stateful\User instance from a parsed Access Token.
*
* @param array $user an array containing the raw Auth0 user data
*/
public function fromAccessToken(array $user): ?Authenticatable {
return User::whereEmail($user['email'])->first();
}
}
Auth0 does not invoke this class.
Models:
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Auth0\Laravel\Contract\Model\Stateful\User as StatefulUser;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableUser;
class Admin implements StatefulUser, AuthenticatableUser
{
use HasFactory, Authenticatable;
...
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Auth0\Laravel\Contract\Model\Stateless\User as StatelessUser;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableUser;
class User implements StatelessUser, AuthenticatableUser
{
use HasFactory, Notifiable, SoftDeletes, Authenticatable;
...
The provider class key should be repository not model; the old key was left over from previous config and our testing with multiple user models before we found Evan’s CustomUserRepository example.