簡體   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