Skip to content
Advertisement

Laravel Passport Get Client ID By Access Token

I’m writing a tiny sms gateway to be consumed by a couple of projects,

I implemented laravel passport authentication (client credentials grant token)

Then I’ve added CheckClientCredentials to api middleware group:

JavaScript

The logic is working fine, now in my controller I need to get client associated with a valid token.

routes.php

JavaScript

For obvious security reasons I can never send the client id with the consumer request e.g. $client_id = $request->client_id;.

Advertisement

Answer

So, no answers …

I was able to resolve the issue by consuming my own API, finally I came up with simpler authentication flow, the client need to send their id & secret with each request, then I consumed my own /oauth/token route with the sent credentials, inspired by Esben Petersen blog post.

Once the access token is generated, I append it to the headers of SymfonyRequest instance which is under processing.

My final output like this:

JavaScript

I used the above middleware in conjunction with Passport’s CheckClientCredentials.

JavaScript

This way, I was able to insure that $request->input('client_id') is reliable and can’t be faked.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement