Shaig Khaligli Shaig Khaligli - 1 month ago 9
PHP Question

Yii2 Login Authenticate without password

I am working on project that will use API of another application. So I won't validate password on my app, will do this via API request. I don't want to store users` passwords in db. Just check password by API.

How can I authenticate a user without login credentials?


Login & Session in Yii 2 is managed by \yii\web\User class This class is accessible in the application life cycle via the \Yii::$app->user property.

On successful authentication using your third-party provider you use the login() function using Yii::$app->user->login($identity)

$identity should be an object of [IdentityInterface][4] usually the User ActiveRecord model implementing this interface

Refer to the guide documentation on Authentication for full understanding on how authentication works in Yii2