robsontenorio / laravel-keycloak-guard

🔑 Simple Keycloak Guard for Laravel
MIT License
434 stars 141 forks source link

How to add Keycloak to laravel #99

Closed abdallahalsamman closed 1 year ago

abdallahalsamman commented 1 year ago

I'm trying to add https://github.com/robsontenorio/laravel-keycloak-guard to my project,

I added a route under the auth:api middleware after installing the above library. but when I go to it I get an "Unauthenticated." error.

    Route::group(["middleware" => "auth:api"], function () {
        Route::get('test', [AuthController::class, 'test']);
    });
    public function test(Request $request)
    {
        dd(Auth::token());
    }

And below is an image showing the exception

enter image description here

The request has an Authorization header of a keycloak access token

enter image description here

I made sure I change my auth guards in config/auth.php like so:

    'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],

    'guards' => [
        'web' => [
            'driver' => 'api',
            'provider' => 'users',
        ],
        'api' => [
            'driver' => 'keycloak',
            'provider' => 'users',
        ]
    ],

What should I do to get the test method to return the correct token?

abdallahalsamman commented 1 year ago

turns out the modheader extension removed my tab filter on it's own so it wasn't sending the Authorization header, solved!