Skip to content
 
 

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel5 Simple OAuth2 Server Package

Software License

Very simple package to use OAuth2 in your Laravel5 app. Package is wrapper around oauth2-php library.

Current features:

TODO:

Install

Require this package with composer (Packagist) using the following command:

$ composer require media24si/simple-oauth2

Register the SimpleOAuth2ServiceProvider to the providers array in config/app.php

'Media24si\SimpleOAuth2\SimpleOAuth2ServiceProvider',

Publish vendor files:

$ php artisan vendor:publish

Migrate your database

$ php artisan migrate

Create route for generating tokens:

$ Route::any('/token', '\Media24si\SimpleOAuth2\Http\Controllers\TokenController@token');

USAGE

Config

When you publish vendor files simpleoauth2.php config file will be copied to config folder. Currently only options to configure are:

  • username field
  • password field
  • additional conditions

SimpleOAuth2 uses Auth::attempt to authenticate user.

Middleware

Package comes with one middleware. To use it, you need to register it app\Http\Kernel.php under $routeMiddleware

'oauth' => '\Media24si\SimpleOAuth2\Http\Middleware\SimpleOAuth2'

Then in your routes you can request valid oauth2 token:

Route::get('/protected', ['middleware' => ['oauth'], function() { return 'Protected resource'; }]);

Because SimpleOAuth2 is using laravel authentication package you can request authenticated user with oauth:

Route::get('/protected', ['middleware' => ['oauth', 'auth'], function() { return 'Protected resource with valid user'; }]);

Artisan commands

oauth2:create-client

$ php artisan oauth2:create-client

Create new oauth2 client.

You will need to provide:

  • client name
  • client redirect uris
  • allowed grant types

oauth2:list-clients

$ php artisan oauth2:list-clients

List all clients.

License

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

About

Laravel 5 Simple OAuth2 Package

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages