Yii2 OAuth2 server implementation of https://oauth2.thephpleague.com/
This extension provides The PHP League: OAuth 2.0 Server module for the Yii2 Framework.
The PHP League: OAuth 2.0 Server is a package that makes setting up a OAuth2 server easy.
The preferred way to install this extension is through composer.
$ composer require wolfpack-it/yii2-oauth
"wolfpack-it/yii2-oauth": "^<latest version>"
require section of your
The basic configuration is a module in your application:
'modules' => [ 'oauth' => [ 'class' => \WolfpackIT\oauth\Module::class, 'userClass' => '<class of ActiveRecordUser implementing UserEntityInterface>', 'db' => 'db', // component that should be used for the database connection 'publicKey' => '<path to public key file te be used by CryptKey, or configuration>', 'privateKey' => '<path to private key file te be used by CryptKey, or configuration>', 'encryptionKey' => '<random string for encryption>', 'tokenValidationLeeway' => null|int, // The number of seconds to use as leeway when validating access tokens ] ]
See the public variables of the Module for the full configuration options.
An example on how to generate keys can be found here.
AccessTokenService is being injected via DI, the module needs to be added to the bootstrap of the application.
The migrations can be ran automatically by adding them to the migration namespaces:
'migrationNamespaces' => [ 'WolfpackIT\oauth\migrations', 'console\migrations', ]
To get this working, you will need to add an alias:
'aliases' => [ '@WolfpackIT/oauth' => '@vendor/wolfpack-it/yii2-oauth/src', ]
If you want to override the database connection in the migrations, you will need to bootstrap the oauth module also in the console.
To have the module accessible, make sure the correct routes are set in your urlManager.
For example when your module is called
'urlManager' => [ 'rules' => [ 'oauth/<controller:[\w-]+>/<action:[\w-]+>' => 'oauth/<controller>/<action>' ] ]
- Add tests
The MIT License (MIT). Please see LICENSE for more information.