我在用戶模型中實現了findIdentityByAccessToken。Yii2 REST API基本身份驗證(SESSION OVERRIDE)
public static function findIdentityByAccessToken($token, $type = null)
{
$apiUser = ApiAccess::find()
->where(['access_token' => $token])
->one();
return self::findOne(['id' => $apiUser->idUser]);
}
在瀏覽器中,如果我登錄到系統,我可以打一個API獲得端點,進入我的身份驗證令牌,並正確進行身份驗證。
但是,如果我沒有登錄,我會被踢回到我的登錄屏幕。使用休息客戶端,我返回了登錄屏幕的HTML。
這表明在我眼中2件事中的1件。無論是在當前狀態下,它都需要一個「登錄會話」才能訪問該api模塊。或#2,我沒有正確傳遞身份驗證令牌。
我的請求頭:
Accept: */*
Cache-Control: no-cache
Authentication: Basic base64('mytoken':)
如何重寫我的 「默認」 的登錄行爲?或正確發送身份驗證令牌?