2017 © Pedro Peláez
 

library simple-oauth2

Laravel 5 Simple OAuth2

image

media24si/simple-oauth2

Laravel 5 Simple OAuth2

  • Monday, February 20, 2017
  • by BostjanOb
  • Repository
  • 2 Watchers
  • 3 Stars
  • 1,137 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 5 % Grown

The README.md

THIS PROJECT IS DEPRECATED. Use Laravel Passport instead

Laravel5 Simple OAuth2 Server Package

Software License, (*1)

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)

Install

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']);

USAGE

Config

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)

Middleware

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)

Grant types

Authorization Code and Implicit

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)

License

The MIT License (MIT). Please see License File for more information., (*17)

The Versions

20/02 2017

dev-master

9999999-dev https://github.com/Media24si/SimpleOAuth2

Laravel 5 Simple OAuth2

  Sources   Download

MIT

The Requires

 

laravel oauth oauth2 laravel 5