Passport client-credential grant to protect register route
I am using Laravel Passport password grant to guard APIs for a mobile. Working great so far. Once I have a password client and an existing user, I can pass oauth/token with [clientID, clientSecret, email, pwd, etc] and get an access token to access the rest of my APIs.
I want to create a register api route (i.e. mysite.com/api/register and not mysite.com/register) so the mobile app can show a native register form instead of just bring up a webview with mysite.com/register url. How do I protect the register api route and make sure only our mobile client can access it? Someone from oauth2-server-laravel suggested that we should use client-credential grant for registration. Does Laravel Passport support client-credential grant? Or is there a better way to protect the route?
@stevenlee I'm having the same issue right now. There are certain endpoints on my API that I only want accessible from my web client. It sounds like the client-credential grant is what we need but that doesn't seem to be part of Passport. Have you come across any solution yet?
I also need this and managed to get half way through so far. What you need to do is POST to /oauth/token and send these parameters: grant_type='client_credentials',
client_id='your_client_it',
client_secret='your_client_secret'
You will get back a new access token.
I just need to figure out, how to authenticate the request that needs client credentials. Hopefully will solve this today.
I'm just wondering how you set the client to be used with the client credentials -
since adding clients requires a user id, and the whole idea of the client credentials is that there is no user.
I used php artisan passport:client and added the user_id of 1.
As the token request only requires the client_id& client_secret, my assumption (MOAFU's) is that the User ID is irrelevant, the token still gets issued even if I null the user_id in the DB and if still there, does not return a user.
I'm using both Passport Grant & Client Credentials in my small API with the Passport Grant being used by an external client to log the user in and the Client Credentials for server to server requests.