繁体   English   中英

laravel 5.8 上的 Auth0 无法验证端点:Auth0\Login\Auth0Service::__construct() 必须是数组类型,null 给出,

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

我尝试在现有的 laravel 5.8 应用程序上使用 auth0 库对端点进行身份验证(我知道我需要认真升级,但没有时间):

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

我做了以下路线:

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);
    });
});

此外,我的auth.php是:

<?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,
        ],
    ],

];

我的设置是:

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/

正如 Api 所说。 然后我通过 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"}'

我使用失眠症执行以下请求:

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

但我收到以下错误:

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

为什么服务提供未初始化的任何想法?

您可以查看 Auth0 的交互式文档并 在此处逐步操作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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