Download the PHP package hosannahighertech/yii2-oauth2-server without Composer
On this page you can find all versions of the php package hosannahighertech/yii2-oauth2-server. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hosannahighertech/yii2-oauth2-server
More information about hosannahighertech/yii2-oauth2-server
Files in hosannahighertech/yii2-oauth2-server
Package yii2-oauth2-server
Short Description OAuth2 Server for PHP a fork of filsh/yii2-oauth2-server
License MIT
Homepage https://github.com/hosannahighertech/yii2-oauth2-server
Informations about the package yii2-oauth2-server
Yii2 Oauth2 Server
A wrapper for implementing an OAuth2 Server(https://github.com/bshaffer/oauth2-server-php). This is a fork of https://github.com/Filsh/yii2-oauth2-server. I decided to fork it after a long standing issue of branches not being resolved at original repo. There is no guarantee that the two will remain compartible so check out things to see if there is anything broke while transiting.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json.
To use this extension, simply add the following code in your application configuration:
Configure User class
- user model implementing an interface , so the oauth2 credentials data stored in user table. Make sure you implement:
-
public function checkUserCredentials($username, $password)
which Checks the supplied username and password for validity and returns TRUE if the username and password are valid, and FALSE if it isn't. public function getUserDetails($username)
which returns array of the associated "user_id" and optional "scope" values something like this:
Additional OAuth2 Flags:
enforceState
- Flag that switch that state controller should allow to use "state" param in the "Authorization Code" Grant Type
allowImplicit
- Flag that switch that controller should allow the "implicit" grant type
The next step your shold run migration
this migration create the oauth2 database scheme and insert test user credentials for
add url rule to urlManager
Usage
To use this extension, simply add the behaviors for your base controller:
Create action authorize in site controller for Authorization Code
https://api.mysite.com/authorize?response_type=code&client_id=TestClient&redirect_uri=https://fake/
For More on Requests and responses as well as explanations for Oauth Grant types see excellet tutorial by Jenkov here: http://tutorials.jenkov.com/oauth2/
Also if you set you can use Implicit Grant Type - see more
Request example:
https://api.mysite.com/authorize?response_type=token&client_id=TestClient&redirect_uri=https://fake/cb
With redirect response:
https://fake/cb#access_token=2YotnFZFEjr1zCsicMWpAA&state=xyz&token_type=bearer&expires_in=3600
JWT Tokens
If you want to get Json Web Token (JWT) instead of convetional token, you will need to set 'useJwtToken' => true
in module and then define two more configurations:
'public_key' => 'app\storage\PublicKeyStorage'
which is the class that implements PublickKeyInterface and 'access_token' => 'OAuth2\Storage\JwtAccessToken'
which implements JwtAccessTokenInterface.php. The Oauth2 base library provides the default access_token which works great. Just use it and everything will be fine.
Here is a sample class for public key implementing PublickKeyInterface
. Make sure that paths to private and public keys are correct. You can generate them with OpenSSL tool with two steps (Thanks to (Rietta)[https://rietta.com/blog/2012/01/27/openssl-generating-rsa-key-from-command/]):
Note that you can copy contents of the files and paste the long strings in class variables. It is nasty but it works fine if that is what you want.
For more, see https://github.com/bshaffer/oauth2-server-php