Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JWT-Authentication of mulitple Laravel-APIs with the same token

Tags:

laravel

jwt

I have a laravel / angular app secured with tymon/jwt-auth.

Now I need a seperate Laravel (or Lumen) API. I want this API to accept the same tokens as the first one. I assumed that this would work if I would set the same secret and mount the middleware.

It doesn't. Using a freshly generated token I can query the first API but not the new one. Why is that? Is something else besides the secret used to verify the token?

What would be a good way to make this work? I would not mind to make a completely new authentication.

Edit: So it seems like a connection to the database is need to verify the token. Maybe it checks if the user specified in the token is actually present in the DB?

Edit2: Tore Nestenius commented about Aud-Claims. I wanted to go to the config/jwt.php file to check on that. But I had forgotten to create one. Now it works.

like image 528
NDDT Avatar asked Jan 19 '26 13:01

NDDT


1 Answers

The aud claim in the token must match what both API's expect to see in the access token. I am glad my comment helped you to solve your issue.

like image 111
Tore Nestenius Avatar answered Jan 22 '26 05:01

Tore Nestenius