Looping to decode multiple JWT tokens in one call

不打扰是莪最后的温柔 提交于 2019-12-13 02:49:54

问题


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?

来源:https://stackoverflow.com/questions/53905239/looping-to-decode-multiple-jwt-tokens-in-one-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!