dev-master
9999999-dev https://github.com/Media24si/SimpleOAuth2Laravel 5 Simple OAuth2
MIT
The Requires
laravel oauth oauth2 laravel 5
Wallogit.com
2017 © Pedro Peláez
Laravel 5 Simple OAuth2
A very simple OAuth2 package to use in your Laravel5 app. The package is a wrapper around the oauth2-php library and is inspired by FOSOAuthServerBundle., (*2)
Current features: - Client credentials grant type - Resource Owner Password Credentials grant type - Refresh token - Grant extensions - Middleware for checking valid token & user, (*3)
TODO: - [ ] Scopes - [x] Authorization Code grant type - [x] Implicit grant type - [ ] Test - [ ] Integration with Travis CI, (*4)
Require this package with composer (Packagist) using the following command:, (*5)
``` bash $ composer require media24si/simple-oauth2, (*6)
Register the SimpleOAuth2ServiceProvider to the providers array in config/app.php ``` php Media24si\SimpleOAuth2\SimpleOAuth2ServiceProvider::class,
Publish vendor files: ``` bash $ php artisan vendor:publish, (*7)
Migrate your database ``` bash $ php artisan migrate
Create a route for generating tokens: ``` php $ Route::any('/token', '\Media24si\SimpleOAuth2\Http\Controllers\TokenController@token');, (*8)
If you want to use Authorization code or Implicit grant type add authore controller to rote: ``` php Route::any('/authorize', ['middleware' => 'auth','uses' => '\Media24si\SimpleOAuth2\Http\Controllers\AuthorizeController@authorize']);
When you publish vendor files, the simpleoauth2.php config file will be copied to the config folder. Currently the only configuration options are: - a username field - a password field - additional conditions, (*9)
SimpleOAuth2 uses Auth::attempt to authenticate users., (*10)
The package comes with one middleware. To use it, you need to register app\Http\Kernel.php under $routeMiddleware
``` php
'oauth' => '\Media24si\SimpleOAuth2\Http\Middleware\SimpleOAuth2', (*11)
Then in your routes you can request a valid oauth2 token: ``` php Route::get('/protected', ['middleware' => ['oauth'], function() { return 'Protected resource'; }]);
Because SimpleOAuth2 is using Laravel authentication package you can request an authenticated user with oauth: ``` php Route::get('/protected', ['middleware' => ['oauth', 'auth'], function() { return 'Protected resource with valid user'; }]);, (*12)
### Artisan commands **oauth2:create-client** ``` bash $ php artisan oauth2:create-client {client_name}
Create a new oauth2 client. For all options see help, (*13)
``` bash $ php artisan help oauth2:create-client {client_name}, (*14)
**oauth2:list-clients** ``` bash $ php artisan oauth2:list-clients
List all oauth2 clients., (*15)
To use authorization code or implicit grant types you have to provide auth middleware so user can login. You can customize authorize by implementing your own action and view., (*16)
The MIT License (MIT). Please see License File for more information., (*17)
Laravel 5 Simple OAuth2
MIT
laravel oauth oauth2 laravel 5