abdurrahmanriyad/lumenauth
A package to implement easy authentication in lumen
22
6
| Install | |
|---|---|
composer require abdurrahmanriyad/lumenauth |
|
| PHP: | >=5.5.9 |
| License: | MIT |
| Last Updated: | Jan 18, 2019 |
| Links: | GitHub · Packagist |
Maintainer: abdurrahmanriyad
lumenAuth
LumenAuth is a simple authentication package for lumen. This enables user to get rid of primary hassle to setup token based authentication in lumen.
Installation
- Install LumenAuth with composer:
composer require abdurrahmanriyad/lumenauth
- Add the following line to bootstrap/app.php file
$app->register(\Abdurrahmanriyad\LumenAuth\LumenAuthServiceProvider::class);
- Add a secret key(anything you want) to LUMEN_AUTH_SECRET in .env which used to build token
LUMEN_AUTH_SECRET=YOUR_SECRET_KEY
eg. LUMEN_AUTH_SECRET=7852ef15dcdd3eaeb40sdfasdf459171556
- If your User model doesn't belong to App\User then add the following line on your .env file
USER_MODEL=YOUR_USER_MODEL_NAMESPACE
eg. USER_MODEL=App\Models\User
Usage
- Add lumenAuth middleware to routes you want authentication
For example,
$router->group(['middleware' => 'lumenAuth'],
function () use ($router) {
//your routes
});
- To generate token for a user you use LumenAuthFacade::getToken($user) which return a token for given user instance.
For example,
use Abdurrahmanriyad\LumenAuth\Facades\LumenAuthFacade;
.......
class AuthController extends Controller {
public function login(Request $request) {
//validate user and check user
........
// Verify the password and generate the token
if (Hash::check($userPassword, $user->password)) {
return response()->json([
'token' => LumenAuthFacade::getToken($user)
], 200);
}
.........
}
}
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Related Packages
johnturingan/laravel-jwt-auth
JSON Web Token Authentication for Laravel 4 and 5. Modification from Tymon's jwt...
4,455
0
themonkeys/laravel-google-auth
Laravel Authentication Driver for Google OAuth authentication
1,863
43