【问题标题】:How to get user details from bearer token laravel api如何从不记名令牌 laravel api 获取用户详细信息
【发布时间】:2021-08-14 16:26:48
【问题描述】:

我无法理解我该怎么做请帮我找到解决方案

$response = $client->request('POST', '/api/profile_update', [
   
     'headers' => [
         'Authorization' => 'Bearer '.$token,
         'Accept' => 'application/json',
      ],
]);
return $response;

我在 api.php 文件中使用了类似的东西

现在我可以在 controller 文件中做什么。

【问题讨论】:

标签: laravel api bearer-token


【解决方案1】:
                  $tokenResult = $user->createToken('Personal token');
                    
                    $token = $tokenResult->token;
                    $token->save();
                    return response()->json([
                        'success'   => true,
                        'access_token' => $tokenResult->accessToken,
                        'token_type' => 'Bearer',
                        'expires_at' => Carbon::parse(
                            $tokenResult->token->expires_at
                        )->toDateTimeString()
                  ]);

【讨论】:

    【解决方案2】:

    您将用户令牌保存在数据库中的用户表中并使用请求中的给定令牌检查它

    如果它们相同,您将获得用户信息

    【讨论】:

    • 这是解决方案吗?
    • 不,这不是解决方案
    猜你喜欢
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 2018-08-12
    • 2016-06-02
    • 2021-04-03
    • 1970-01-01
    • 1970-01-01
    • 2016-12-31
    相关资源
    最近更新 更多