Issue
I'm passing to the server in the POST request body the Token of the user. I need to find out which user this token belongs to. In laravel/sanctum documentation I found out that it is possible to do it only by putting the Token as "Authorization": "Bearer ****" header. But it is not my case, I need to pass it in the POST body. Is there a way to do so?
Solution
I found a solution by making a few experiments and reading the source code of Sanctum. User's data is possible to get by token in POST data in that way:
$post_data = $request->all();
if (isset($post_data['user_token'])) {
[$id, $user_token] = explode('|', $post_data['user_token'], 2);
$token_data = DB::table('personal_access_tokens')->where('token', hash('sha256', $partner_token))->first();
$user_id = $user_id->tokenable_id; // !!!THIS ID WE CAN USE TO GET DATA OF YOUR USER!!!
}
Answered By - Dmytro Huz Answer Checked By - David Goodson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.