Laravel Passport Multiple Authentication using Guards

前端 未结 4 526
说谎
说谎 2020-12-09 06:54

Can we use laravel passport with different guards to authenticate APIs for two different types of users. For example we have driver app for driver user and vendor app for ve

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-09 07:00

    You don't necessarily need to change config for each request. You need a client for each guard. After creating clients by running

    passport:install
    

    Make sure you specified provider field in database. It should be same value as auth.providers config.

    After creating clients and guards, use following code when creating an access token.

    App::clearResolvedInstance(ClientRepository::class);
    app()->singleton(ClientRepository::class, function () {
        return new ClientRepository(User::CLIENT_ID, null); // Client id of the model
    });
    

    Make sure you specified provider in oauth_clients table.

提交回复
热议问题