I'm trying to create rest api for my application to get the data in my android app. This is my controller
<?php
namespace api\modules\v1\controllers;
use yii\rest\ActiveController;
use yii\filters\auth\QueryParamAuth;
/**
* Tk103 Controller API
*/
class Tk103Controller extends ActiveController
{
public $modelClass = 'api\modules\v1\models\Tk103CurrentLocation';
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => QueryParamAuth::className(),
];
return $behaviors;
}
}
I added access_token
column in my user table, implemented findIdentityByAccessToken()
in User Model and calling this URL
http://localhost:7872/api/v1/tk103s?access-token=abcd
This is working great and returning data if and only if access_token
matches with any single user in the table.
I checked QueryParamAuth class and found that QueryParamAuth::authenticate()
returns $identity
after successful authentication.
Currently this url is returning whole data of my table.
What I want is(after authentication):
- Get user id/username of the requester.
- Based on that id/username, the data related to him as per relations of tables in db. (currently whole rows are being returned but I want only few that are matching with the current requester/user)
I tried but didn't getting any clue to catch returned $identity
of user after authentication.
And I know it is possible too to make this work. Help me out folks to create magic.