简体   繁体   English

从API登录Laravel错误token_not_provided JWT

[英]Error token_not_provided JWT in Laravel login from API

I get token but the problem is when redirected this error will happened : token_not_provided 我得到令牌,但问题是重定向时将发生此错误:token_not_provided

$client = new \GuzzleHttp\Client();

    $res = $client->request('POST', 'http://localhost:3000/api/login', [
        'form_params' => [
             "email"        => 'niakan@gmail.com',
             "password"     => '123456',
        ]
    ]);

    $res = json_decode( $res->getBody() );
    $token = $res->data->token;

    if ( $res->status == "success" ) {
        $request->headers->set('Authorization', "Bearer $token");
        return redirect('/test2');
    } else {
        abort( 404 );
    } 

you need to insert the token, not string of "$token". 您需要插入令牌,而不是“ $ token”字符串。

if ( $res->status == "success" ) {
    $request->headers->set('Authorization', "Bearer ". $token);
    return redirect('/test2');
} else {
    abort( 404 );
} 

note the 注意

$request->headers->set('Authorization', "Bearer ". $token);

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

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