【问题标题】:PHP-JWT user in token令牌中的 PHP-JWT 用户
【发布时间】:2018-07-30 17:51:59
【问题描述】:

在我的 php api(框架流明)中,我正在检索用户数据和令牌。 我想将此用户数据放入哈希令牌中。

我当前的代码如下所示:

    if (! $token = $this->jwt->attempt($request->only('email', 'password'))) {
        return response()->json(['user_not_found'], 404);
    }

    $user = $this->jwt->user();

    return response()->json(compact('token', 'user'));

【问题讨论】:

  • 这些方法是什么? jwt->attempt($request->only
  • $token->data->user->id...

标签: php laravel jwt lumen


【解决方案1】:

你可以像这样使用散列数据

                   $key= "User access token";                  // create a key

                    $hash_data= array(
                    "email" => $email,
                    "password" => $password,
                );

               $access_token = JWT::encode($hash_data, $key);
               return response()->json(compact('token', 'access_token '));

$access_token 中的详细信息将采用 加密 格式,当您只想对其进行解码时

【讨论】:

  • 是的,但我想把它全部放在一个变量中 - 令牌。在 nodejs 我可以这样做: const token = jwt.sign({ user: user }, process.env.SECRET_TOKEN);
  • 在 $access_token 中,您可能会找到一个令牌(加密的电子邮件和密码)。两者都在一个变量中。当你解码它时,你会得到数组中的电子邮件和密码
  • 重点是我不想创建$access_token,而是想把用户数据放到现有的$token中
猜你喜欢
  • 2023-01-27
  • 2017-09-11
  • 2017-03-22
  • 1970-01-01
  • 2018-08-14
  • 2016-10-08
  • 2015-09-19
  • 1970-01-01
  • 2020-10-20
相关资源
最近更新 更多