dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.33k stars 1.25k forks source link

How to use middleware with multiple auth provider? #1786

Closed wendy-rose closed 2 years ago

wendy-rose commented 2 years ago
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?

specialtactics commented 2 years ago

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) {
    });
wendy-rose commented 2 years ago

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.

wendy-rose commented 2 years ago

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.