0

I get token but the problem is when redirected this error will happened : token_not_provided

$client = new \GuzzleHttp\Client();

    $res = $client->request('POST', 'http://localhost:3000/api/login', [
        'form_params' => [
             "email"        => '[email protected]',
             "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 );
    } 
3
  • look this stackoverflow.com/questions/36427106/… Commented Jun 26, 2018 at 7:45
  • I want user be login by jwt after requested to api and set Authorization, but didn't works Commented Jun 26, 2018 at 7:50
  • It works with : return redirect('/test2/?token=' . $token); Commented Jun 26, 2018 at 8:06

1 Answer 1

1

you need to insert the token, not string of "$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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.