0

I'm using Laravel to create an API. Then I want another Laravel instance to authenticate users using the api.

So my api contains all the users. The client doesn't know anything. I want to have a form (just username and password) and send that data to the api and if the user exists, log in to the client.

I have read the docs about laravel passport but I don't really get how I should use it from the client side. Can anyone explain to me how I can check if a user exists in my api and keep the user logged in from my api?

  • You can also use `jwt` – Zain Farooq Oct 08 '19 at 07:40
  • Could you please explain a bit more about that? I'm totally new to building an API at all –  Oct 08 '19 at 07:45
  • Passport is easy to use just read this tutorial https://medium.com/techcompose/create-rest-api-in-laravel-with-authentication-using-passport-133a1678a876 – Eyad Jaabo Oct 08 '19 at 08:20
  • @EyadJaabo Yeah I have all of that working. But I can't figure out how the client app should stay logged in when receiving the response. How do I conntect the 2 applications? –  Oct 08 '19 at 08:31
  • Just save the `token` when you got it and check `if ($token)` not expired `{nextPageAfterLoginPage}` – Eyad Jaabo Oct 08 '19 at 10:53
  • Or if the second application, for example, android you can do something like `if ($token)` `Intenet to secondActivity` else `loginPage` – Eyad Jaabo Oct 08 '19 at 10:56
  • Yeah it sounds pretty simple. But I feel like I need to rewrite the whole login procedure of Laravel. It also feels like that a lot of work which should be a lot easier then I think at the moment. I want my authentication and authorisation to happen at the API side, not the client side –  Oct 09 '19 at 12:35
  • Hi, is this https://stackoverflow.com/questions/61980446/how-do-we-implement-custom-api-only-authentication-in-laravel/61980447 helpful? – quinny Mar 19 '21 at 12:12

0 Answers0