I am starting to use yii2 and I am providing a REST Api
from the web app. I could not find any documentation on how to provide login functionality using yii2 REST api.
Previously in yii1
, we used to have an action called actionLogin
which takes in a username and password and authenticate it(with User model).
Is that the same approach still with yii2
? Like in UserController
(under the Api module) have an actionLogin
method with GET request type and once authenticated successfully return User object
(with access token for subsequent calls?) ?
Well, it looks like creating an actionLogin method and that takes in username and password is still the way to go on yii2 (confirmed from yii2 developers). Also, you have to either exclude the actionLogin from authentication behaviors and there are couple of ways it could be done(either through override before action and not calling authenticate method, and the other approach is to add this actionLogin method in some controller which does not describe the authentication behavior).