Login user by using REST API instead of Database

Dear,

I am currently writing a front-end application that will communicates with a separate backend application (on an another server) by using a REST API.

Now I like to login a user on the frontend app by using the REST API for authenticating and needed data. All the users are stored in the database of the backend app.

How can I do this, on the internet I only found examples where a database is used, how can I implement my REST backend for the login process. The database where the info is stored is looking like this;

id (PK)

email (username)

password (password)

(and a lot of other fields that are not relevant)

The API itself is also based on Yii2 and managed by me, so I can create new actions there if needed for providing the right data.

Thanks in advance.

Your REST API is effectively a database layer for your application. So in your User model instead of db to get user data - just call your API instead of db. You probably can’t use IdentityInterface implementation directly, but you can easily change it to authenticate user by REST call that takes username and password and returns access-token, that you can use later on to call API. I did something similar, althrough I’m hosting everything within one provider so in my frontend I still use my db to authenticate user.

Hi,

Do you have an example or steps on how to apply this?

I am currently working on a Frontend web app right now and the login and logout must be processed from an api(login API and logout API). I am quite not sure how to start with it.

Regards,
J