[英]How to get user details from bearer token laravel api
我無法理解我該怎么做 請幫我找到解決方案
$response = $client->request('POST', '/api/profile_update', [
'headers' => [
'Authorization' => 'Bearer '.$token,
'Accept' => 'application/json',
],
]);
return $response;
我在api.php
文件中使用了類似的東西
現在我可以在controller
文件中做什么。
$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()
]);
您將用戶令牌保存在數據庫中的用戶表中,並使用請求中的給定令牌檢查它
如果它們相同,您將獲得用戶信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.