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

guard in auth problem #1541

Open morningmemo opened 6 years ago

morningmemo commented 6 years ago
Q A
Bug? no
New Feature? no
Framework Laravel
Framework version 5.5.y
Package version 2.0.0-alpha2
PHP version 7.1.y

config/auth.php

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'TLXAdminUsers',
        ],

        'user' => [
            'driver' => 'jwt',
            'provider' => 'Users',
        ],

        'staff' => [
            'driver' => 'jwt',
            'provider' => 'Staff',
        ]
    ]

config/api.php

'auth' => [
        'jwt' => 'Dingo\Api\Auth\Provider\JWT'
    ],

Kernel.php

protected $routeMiddleware = [
        'api-auth' => \Dingo\Api\Http\Middleware\Auth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \Studiomate\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,

        'role' => \Laratrust\Middleware\LaratrustRole::class,
        'permission' => \Laratrust\Middleware\LaratrustPermission::class,
        'ability' => \Laratrust\Middleware\LaratrustAbility::class
    ];

I want to use 'staff' guard and 'user' guard in 'dingo auth' with 'jwt' on the route. However, 'dingo auth' using 'jwt' seems to be able to use only the defaults defined in config / auth.php. Is there a way to use 'staff' guard and 'user' guard on a route?

I know how to use 'auth:staff' on middleware by defining

'auth' => Illuminate\Auth\Middleware\Authenticate::class'

on routeMiddleware, This is also a problem because of an 500 error not 401 error.

dbing commented 5 years ago

Have you solved your problem?

whw2016 commented 5 years ago

wait

mith495 commented 5 years ago

I will have a look at it.