PHP code example of roaresearch / yii2-oauth2-server
1. Go to this page and download the library: Download roaresearch/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/ */
use OAuth2\Storage\UserCredentialsInterface;
use roaresearch\yii2\oauth2server\{
RevokeAccessTokenInterface,
RevokeAccessTokenTrait,
};
class User extend \yii\db\ActiveRecord implement
UserCredentialsInterface,
RevokeAccessTokenInterface
{
use RevokeAccessTokenTrait; // optional, trait with default implementation.
// rest of the class.
}
public function behaviors()
{
return [
'revokeToken' => [
'class' => \roaresearch\yii2\oauth2server\filters\RevokeAccessToken::class,
// optional only revoke the token if it has any of the following
// scopes. if not defined it will always revoke the token.
'scopes' => ['author', 'seller'],
// optional whether or not revoke all tokens or just the active one
'revokeAll' => true,
// optional if non authenticated users are permited.
'allowGuests' => true,
// which actions this behavior applies to.
'only' => ['create', 'update'],
],
];
}
use roaresearch\yii2\oauth2server\actions\AuthorizeAction;
class SiteController extends Controller
{
public function actions()
{
return [
'authorize' => [
'class' => AuthorizeAction::class,
'loginUri' => ['site/login'],
'viewRoute' => 'authorize',
'oauth2Module' => 'api/oauth2',
],
];
}
}