简体   繁体   中英

Auth0 upon laravel 5.8 unable to authenticatean entpoint: Auth0\Login\Auth0Service::__construct() must be of the type array, null given,

I try to authenticate an endpoint using the auth0 library on an existing laravel 5.8 application (I know I need a serious upgrade but ain't got time):

$ composer require auth0/login
$ php artisan vendor:publish --tag=auth0-config

And I made the following route:

Route::prefix('/test')->middleware(['auth0.authenticate'])->group(function(){
    Route::get("/hello",function(){
        return response()->json([
            'message' => 'Hello from a private endpoint! You need to be authenticated to see this.',
            'authorized' => Auth::check(),
            'user' => Auth::check() ? json_decode(json_encode((array) Auth::user(), JSON_THROW_ON_ERROR), true) : null,
        ], 200, [], JSON_PRETTY_PRINT);
    });
});

Furthermore my auth.php is:

<?php

return [
    'defaults' => [
        'guard' => 'auth0',
        'passwords' => 'users',
    ],

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

        'api' => [
            'driver'   => 'token',
            'provider' => 'users',
        ],


        'auth0' => [
            'driver' => 'auth0',
            'provider' => 'auth0',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model'  => App\User::class,
        ],
        'auth0' => [
            'driver' => 'auth0',
            'repository' => \Auth0\Laravel\Auth\User\Repository::class
        ],
    ],
    
    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table'    => 'password_resets',
            'expire'   => 60,
        ],
    ],

];

My settings are:

AUTH0_STRATEGY=api
# The URL of your Auth0 tenant domain
# You'll find this in your Auth0 Application's settings page.
AUTH0_DOMAIN=dev-XXXXXXX.eu.auth0.com

# Your Auth0 application's Client ID
# You'll find this in your Auth0 Application's settings page.
AUTH0_CLIENT_ID=XXXXXXXXX

# Your Auth0 Custom API identifier/audience.
# You'll find this in your Custom API's settings page.
AUTH0_AUDIENCE=https://etable.local/test/

As Api says. Then I perform the following request via curl:

curl --request POST \
 --url https://dev-gv9fxa52.eu.auth0.com/oauth/token \
 --header 'content-type: application/json' \
 --data '{"client_id":"XXXXXXX","client_secret":"XXXXXXXX",
 "audience":"https://etable.local/test/",
 "grant_type":"client_credentials"}'

And I perform the following request using insomnia:

GET https://api.local/test/hello
Authorization: Bearer ^bearer from api above^

But I get the following error:

Argument 1 passed to Auth0\Login\Auth0Service::__construct() must be of the type array, null given, called in /var/www/html/api/vendor/auth0/login/src/Auth0/Login/LoginServiceProvider.php on line 68

Any ideas why Service provides it not initialised?

you can check Auth0's interactive docs and follow step by step here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM