Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Database Id From Generated Token

Currently I am building rest API using Laravel. For authentication, I am using the Sanctum package. Every time a user is logged in it generate a token that looks like this:

"token": "98|b45h97e17VVpugjO71wwURoicIqDQP2ejTkCWwoD" 

But why Sanctum includes the database id with the token?

enter image description here

How to remove the database id from the token?

like image 545
Biswajit Biswas Avatar asked May 01 '26 01:05

Biswajit Biswas


2 Answers

I just looked through the source history and found that the ID was introduced in a well-named commit called more performant tokens lookup, so that is the reason the ID is part of the token.

But if you look at the code loading/verifying the token there is a fallback at the beginning in case there is no ID. So you can simply remove it from the token, for example by overriding the findToken method.

like image 165
Thomas Avatar answered May 03 '26 17:05

Thomas


try this,

Option 1:-

In Controller:-

$token = $user->createToken(''project_name')->plainTextToken;
$auth_token = explode('|', $token)[1];

Option 2:-

In postman Refer image:-

enter image description here

like image 34
Yudiz Solutions Avatar answered May 03 '26 17:05

Yudiz Solutions



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!