dingo / api

A RESTful API package for the Laravel and Lumen frameworks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use middleware with multiple auth provider?

wendy-rose opened this issue · comments

Q A
Bug? no
New Feature? no
Framework Laravel
Framework version 7.x.y
Package version 3.x.y
PHP version 7.x.y

Actual Behaviour

I wrote about two service providers,then set to config/api.auth,

'auth' => [
        'custom' => App\Providers\ApiAuthProvider::class,
        'admin => App\Providers\AdminAuthProvider::class
  ],

now, I want to use admin, but how to use middleware? Use api.auth middleware?

commented

Can you please clarify what you mean?

If you are asking how can you use this list of auth providers, then yes it is by using the api.auth middleware as you mentioned. For example, put all authenticated routes under a group with this middleware like so:

    $api->group(['middleware' => ['api.auth']], function (Router $api) {
    });

Can you please clarify what you mean?

If you are asking how can you use this list of auth providers, then yes it is by using the api.auth middleware as you mentioned. For example, put all authenticated routes under a group with this middleware like so:

    $api->group(['middleware' => ['api.auth']], function (Router $api) {
    });

Thank you!My mean is that I want to use AdminAuthProvider, because of some interfaces need to use AdminAuthProvider, other interfaces need to ApiAuthProvider。So How to differentiated to use different of provider.

Can you please clarify what you mean?

If you are asking how can you use this list of auth providers, then yes it is by using the api.auth middleware as you mentioned. For example, put all authenticated routes under a group with this middleware like so:

    $api->group(['middleware' => ['api.auth']], function (Router $api) {
    });

Thank you!My mean is that I want to use AdminAuthProvider, because of some interfaces need to use AdminAuthProvider, other interfaces need to ApiAuthProvider。So How to differentiated to use different of provider.