We'd like to use Laravel Sanctum to issue API keys / personal access tokens for users, with some modifications:
- Associate an
AccessRestriction with each token, which is simply a model whose properties would define security-related authorization rules for the key (such as the HTTP referrer or IP address the request must come from).
- Add two or three columns to the
personal_access_tokens table, so we can store additional metadata for each token (or at least the id of some model where we'd store that, such as PersonalAccessTokenMetadata)
- The ability to deny the API request based on throttling/quotas
I'm also unclear about how the abilities property works, especially if we're using something like spatie/laravel-permission to further determine what the API key is authorized to do.
For the added DB table columns, I suppose we could simply override Sanctum's default migration.
And I assumed that we could create separate middlewares for authorizing based on referrer/IP and for checking against rate limits - then require all API requests to first go through the auth:sanctum middleware for authentication and then those additional middlewares for authorization.
However, I'm a little fuzzy on how we would need to extend Sanctum and get all of this to work together, and just looking for some guidance.
There's an argument that we just roll our own key generation and management system. After all, the only thing Sanctum is really doing is creating a hash of a randomized 80-char string.
Thank you for any advice or guidance!