Skip to content

chervand/yii2-oauth2-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yii2 OAuth Server

chervand/yii2-oauth2-server is a Yii2 PHP Framework integration of n integration of thephpleague/oauth2-server. It additionally provides MAC tokens support.

Contributions and roadmap

It currently supports only client_credentials grant with Bearer and MAC tokens (both JWT signed with RSA key).

Contributions are welcome, so if you want to implement any missing feature or add any improvement, please open a PR against master branch.

Setup

Apply DB migrations

./yii migrate --migrationPath="@vendor/chervand/yii2-oauth2-server/migrations"

Generating public and private keys

See OAuth 2.0 Server installation page.

Authorization server

Configure the module:

...
    `modules` = [
        'oauth2' => [
            'class' => \chervand\yii2\oauth2\server\Module::class,
            'privateKey' => __DIR__ . '/../private.key',
            'publicKey' => __DIR__ . '/../public.key',
            'userRepository' => \app\components\UserRepository::class,
            'enabledGrantTypes' => [
                new \League\OAuth2\Server\Grant\ImplicitGrant(new \DateInterval('PT1H')),
                new \League\OAuth2\Server\Grant\ClientCredentialsGrant(),
            ],
        ],
...

Add the module to application's bootstrap:

...
'bootstrap' => ['oauth2'],
...

Resource server

Configure controllers behaviors:

    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['authenticator'] = [
            'class' => CompositeAuth::class,
            'authMethods' => [
                [
                    'class' => HttpMacAuth::class,
                    'publicKey' => $publicKey
                ],
                [
                    'class' => HttpBearerAuth::class,
                    'publicKey' => $publicKey
                ],
            ]
        ];
        return $behaviors;
    }

About

OAuth 2.0 Server for Yii 2.0 with MAC Tokens and Tokens Revocation support

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages