Looping to decode multiple JWT tokens in one call

2019-08-28 19:36发布

We have an in-house API service that, when called with an email and password, checks for the user and sends back several JWTs (JSON web tokens).

I currently have my modified login function in the main laravel AuthController that sends the data from my login form to the API call, and upon submission, I've dumped the 4 tokens.

Dumped Tokens:

{#719 ▼
  +"access": "...token..."
  +"check": "...token..."
  +"permission": "...token..."
  +"secondary": "...token..."
}

The problem is, after integrating use \Firebase\JWT\JWT; and trying to dump the decoded version of my Tokens like so:

public function login(Request $request)
{

    $key = "publicKey";

    $this->validate($request, [
        'email' => 'required',
        'password' => 'required',
    ]);

    $credentials = $request->only('email', 'password');

    $email = $request->input('email');
    $password = $request->input('password');

    $authService = new AuthService();
    $login = $authService->loginGetToken($email, $password);

    $decoded = JWT::decode($login, $key, array('HS256'));
    dd($decoded);

    return redirect(route('auth.login'))
        ->with('login', $login);
}

I get an error about wrong number of segments.

Now, if I copy any one of the tokens into the $login variable then it dumps decoded just fine, so it's obviously because I have multiple tokens in one call.

How can I decode all 4 of these JWTs properly so that I can cache them and access their info? Is there a way to loop or iterate these?

0条回答
登录 后发表回答