laravel / sanctum

Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.
https://laravel.com/docs/sanctum
MIT License
2.74k stars 294 forks source link

Add regenerateToken method to HasApiTokens #509

Closed FatefulNur closed 5 months ago

FatefulNur commented 5 months ago

This PR introduces new regenerateToken method to the HasApiTokens traits in Laravel Sanctum. This method allows users to regenerate a new personal access token while revoking the existing one.

Changes:

Use-Case

For scenarios requiring frequent rotation of access tokens to mitigate security risks, the addition of a regenerateToken method to Laravel Sanctum can greatly simplify token management without manually creating it into our own model.

Testing:

A unit test have been added to ensure the proper functionality of the regenerateToken method.

RahulDey12 commented 5 months ago

why it's deleting all the token it should delete the transit token instead of all.

FatefulNur commented 5 months ago

@RahulDey12 thanks for your advice. Could you tell what's the regard to delete only the transient token?

RahulDey12 commented 5 months ago

It mean that we are logging out.

FatefulNur commented 5 months ago

May be the idea wasn't relevant with api tokens.