"findIdentityByAccessToken" is not implemented

Hi,

I started working on a REST API and I’ve noticed that the “findIdentityByAccessToken” function of the common\model\User.php is not implemented. Can I please ask the reason for this?

Here’s the exact location: https://github.com/yiisoft/yii2/blob/master/apps/advanced/common/models/User.php#L74

Thanks!

Ric B,

You need to implement it.

Now, in YII 2 there’s a interface to do the Authentication and Autorization: IdentityInterface.

So, if you have a Model that controls this, just implements and then, implement the method findIdentityByAccessToken.

Something that i did:


    public static function findIdentityByAccessToken($token, $type = null) {

        $access = Access::find()

            ->where(['desc_token' => $token])

            ->one();


        return isset($access) ? $access->getUser()->one() : null;

    }

Cool, thanks.

I’ve currently used the following code:


public static function findIdentityByAccessToken($token, $type = null)

    {

        return static::findOne(['auth_key' => $token]);

    }