Hello.
I'm currently experimenting with API powered websites. Currently I have two sites:
Basic API with Laravel 5.2 along with the tymondesigns/jwt-auth and dingo/api packages. The API handles the creation, updating, deletion, and authentication of users.
The Client site is just a vanilla version of Laravel 5.2.
Everything is working well. I have a class within the Client which uses cUrl to communicate with the API site. At the moment I’m handling authentication by:
- sending user login credentials to the API site through cUrl.
- on the API using JWT’s function to check if the user’s credentials are valid.
- if they are valid, retiring the token to the Client site.
- storing the token as a cookie.
- all future requests send the token stored in the cookie using the headers i.e. “Authorization: Bearer”
This works, but I can’t help think that there is a better and more secure way. I’ve read about creating my own authorisation guards. But every tutorial I’ve read so far expects the API to exist within the same code base as the Client.
Ideally, I would like to use the Auth Facade in the Client to check the logged in user or retrieve their details i.e. Name & Email. Otherwise I would have to have to call the API every time I wanted to retrieve their details or check they were logged in.
Does anyone have any experience with this or any tips?
Thanks,
Thom