What are the best practices for api authentication for B2B?
I've an API built on laravel and I want to provide access to api to a third party application. What is the best way to achieve this? I'm using Laravel Passport. Thanks.
Laravel Passport offers different ways to authenticate. For B2B I would probably use the Password Grant Client approach
So the party that integrates get's the client_id and client_secret. They can use that to retrieve an access_token and refresh_token. They can use it until the token is expired and then they need to request a new token.
@bobbybouwmann thank you so much for your suggestion, I have a another question, is there a way we can configure the access_token expiry per client base. So that I can set the token expiry different for each client.
@bobbybouwmann is there anyway we can assign a Password Grant Tokens to a particular a user? Because I wanna have control over who own the client_id and client_secret and I should be able to revoke it.
@bobbybouwmann Sorry, I must have not explained correctly. I meant, can we manage the client_id and client_secret per user basis. so where I can list out all the client_id and client_secret keys along with user details to whom the client_id and client_secret were assigned.
I want to manually revoke the client_id and client_secret details, because I'm building some kind of subscription system. If client doesn't pay the amount I want to revoke access to it.
The client_id and client_secret are stored in a table that is also connected to the user. You already have this data available. You can simply set the revoked column to 1 to revoke a client secret. Check the oauth_clients table
@bobbybouwmann thanks for your time. yes, but when I create the password grant token using php artisan passport:client --password it won't take the user_id, so this is where I got confused on how to assign user_id to the client_id and client_secret. Is there any alternative to generate client_id and client_secret along with user_id?
Aah. The password grant is not meant for this. The idea is for example that you have a mobile app that authenticates with your application. The mobile app knows the client_id and client_secret. Then the users log in my providing the user name and password. All of that data is send to your API which checks it and returns the access token. So a password grant is not connected to a specific user.
If you want to connect the token directly to the user you need to use this
@bobbybouwmann thanks, so, previously you suggested password grant token is good for B2B use-case, now as I can't assign this to user_id, can you suggest an alternative for my scenario where any third party website who consumes the api, that would be much appreciated.