Answer the question
In order to leave comments, you need to log in
Yii How to make authentication from backend or frontend in Rest API?
Hello! I want to use api in the project as internal use. Perhaps for external use later ... I
set everything up according to the webinar from Dmitry Eliseev ( https://www.youtube.com/watch?v=jDj_JggZXsU ).
Everything works, but I just don’t want to manually write a token every time or pass a login or password if I make a request from the backend or frontend. Can you tell me how to use api in conjunction with backend or frontend ? For example, so that after authorization on the backend or frontend and, subsequently, using requests to api, it does not require you to enter a username and password, and also not to pass a username and password or a token in an ajax request.
Perhaps you need to completely refuse authorization in the session and cookies? Or I shouldn't bother with api to implement internal selections via ajax. Create a common controller for this and receive data there. What do you think?
Answer the question
In order to leave comments, you need to log in
using requests to api did not require entering a login and password, and also did not pass a login and password or a token in an ajax request.
I did not watch the video, but you can check if the user is logged in like this:
if(!Yii::$app->user->isGuest) {
...
}
if (Yii::$app->user->identity->id == 'username') {
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question