Firebase令牌:什么是承载者?

时间:2019-12-04 10:12:13

标签: php laravel firebase-authentication jwt lumen

我正在使用此参考资料库来测试流明内部使用firebase令牌的身份验证: https://github.com/alinnert/lumen-auth-reference

我在说明中将头部缠住这部分时遇到麻烦:

GET /secret
  Header:
    Authorization: "Bearer ...token..."

我正在使用RESTClient(www.restclient.net)通过http请求来激发我的Lumen后端。 在这里,我可以定义自定义标题,这可能就是我在这里需要做的。 因此,我这样做了,我将输入字段的名称设置为“ authorization”,并且它已经为我提供了自动补全功能,所以我想这是正确的。 然后,我移到属性值字段并输入

承载者...代币...

现在,当我发送请求时,我得到以下响应:

UnexpectedValueException in JWT.php line 79: Wrong number of segments

    in JWT.php line 79
    at JWT::decode('Bearer...token...', 'pawifjopawiejfpoaiwejfpoji', array('HS256')) in AuthServiceProvider.php line 36
    at AuthServiceProvider->App\Providers\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in RequestGuard.php line 54
    at RequestGuard->user() in GuardHelpers.php line 49
    at RequestGuard->check() in GuardHelpers.php line 59
    at RequestGuard->guest() in Authenticate.php line 38
    at Authenticate->handle(object(Request), object(Closure)) in Pipeline.php line 148
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in Pipeline.php line 102
    at Pipeline->then(object(Closure)) in RoutesRequests.php line 780
    at Application->sendThroughPipeline(array('App\\Http\\Middleware\\Authenticate'), object(Closure)) in RoutesRequests.php line 626
    at Application->handleFoundRoute(array(true, array('middleware' => array('auth'), 'uses' => 'App\\Http\\Controllers\\SecretController@index'), array())) in RoutesRequests.php line 528
    at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 783
    at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 534
    at Application->dispatch(null) in RoutesRequests.php line 475
    at Application->run() in index.php line 28

我不知道我是否只是语法错误,或者是否需要提供句点所在的实际数据。 所以代替

承载者...令牌...

承载者:令牌:

对于那些想尝试一下的人: 在“ SecretController.php”中,您需要将代码更改为:

<?php

namespace App\Http\Controllers;

//use Illuminate\Http\Request;


use App\User;
use Firebase\JWT\JWT;
use Illuminate\Http\Request;
use Illuminate\Http\Response;


class SecretController extends Controller
{
  public function index(Request $request)
  {
    return new Response('Hello ' . $request->user()->name,
      200, ['Content-Type', 'text/plain']);
  }

  public function pub()
  {
    return new Response('Hello World', 200, ['Content-Type', 'text/plain']);

  }
}

否则,您将无法使用web.php中定义的获取路由

0 个答案:

没有答案