PHP code example of niolab / yii2-oauth2-server
1. Go to this page and download the library: Download niolab/yii2-oauth2-server library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
niolab / yii2-oauth2-server example snippets
/**
* {@inheritdoc}
*/
public static function findIdentityByAccessToken($token, $type = null) {
return static::find()
->where(['user.status'=>static::STATUS_ACTIVE])
->leftJoin('oauth_access_token', '`user`.`id` = `oauth_access_token`.`user_id`')
->andWhere(['oauth_access_token.identifier' => $token])
->one();
}
$config = [
'modules' => [
'oauth2' => [
'class' => NIOLAB\oauth2\Module::class,
'userRepository' => \app\models\User::class,
'privateKey' => '@common/data/keys/private.key',
'publicKey' => '@common/data/keys/public.key',
'encryptionKey' => 'put-a-nice-random-string-here',
],
],
];
...
'bootstrap' => ['log','api.v1',...,'oauth2'],
...
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::class,
];
$behaviors['contentNegotiator'] = [
'class' => 'yii\filters\ContentNegotiator',
'formats' => [
'application/json' => Response::FORMAT_JSON,
]
];
return $behaviors;
}
bash
php yii migrate --migrationPath=@vendor/niolab/yii2-oauth2-server/migrations