evertonto / epsoftware-jwt-auth by everton_to

Auth with jwt
26
1
2
Package Data
Maintainer Username: everton_to
Maintainer Contact: everton_to@live.com (Everton de Paula)
Package Create Date: 2016-11-15
Package Last Update: 2017-06-01
Language: PHP
License: MIT
Last Refreshed: 2024-11-23 03:11:38
Package Statistics
Total Downloads: 26
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 1
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

epsoftware-jwt-auth

JWT LUMEN IMPLEMENTATION - BASED https://github.com/lcobucci/jwt

Install Instructions

1 - Uncoment in bootstrap/app.php
	- `$app->withFacades();`
	- `$app->withEloquent();`

2 - Create Class alias in bootstrap/app.php
	 - `$app->alias('App', 'Illuminate\Support\Facades\App');`

3 - Enable configures in bootstrap/app.php
	- `$app->configure('epsoftware-jwt-auth');`

4 - Create file in config folder `epsoftware-jwt-auth.php`
	- ` return [
	        'providers' => [
	            'model' => env('AUTH_MODEL', '\App\User'),
	            'field' => env('AUTH_FIELD', 'id')
	        ],

			'token'  => [
				'type' => env('AUTH_TOKEN_TYPE', 'Bearer')
			],

	        'iss'    => env('AUTH_ISS', ''),
	        'sub'    => env('AUTH_SUB', ''),
	        'aud'    => env('AUTH_AUD', ''),
	        'exp'    => env('AUTH_EXP', 600),
	        'nbf'    => env('AUTH_NBF', 1),
	        'jti'    => env('AUTH_JTI', ''),
	        'secret' => env('AUTH_SECRET', 'somesecretkey')
		];
	`
5 - Register Provider in bootstrap/app.php
	 - `$app->register(\Epsoftware\Auth\Providers\AuthServiceProvider::class);`

6 - Register the middleware in bootstrap/app.php
	- `$app->routeMiddleware([
	   	'jwt-auth'  => \Epsoftware\Auth\Middlewares\MiddlewareAuth::class,
		]);`

	- Remember it, On midddleware alias don't use reseverd names, like `'auth'`

7 - In `.env` make parameters `AUTH_something`
	- `AUTH_SECRET=somesecretkey`

Use Instructions

1 - Set middleware on Routes if you want to authenticate

	- Set middleware with yours 'alias'
		`$app->get('/route', ['middleware' => 'jwt-auth', 'uses' => 'Controller@get']);`

	- Required `Bearer Token` in Request Header Authorization

2 - Use Facades for get user

	- `$user = \Epsoftware\Auth\Facades\Auth::getUser());` returns `User object`
	- `$user->id` 	 || '1'
	- `$user->name` || 'Tom'

3 - Authentication user

	` if (\Epsoftware\Auth\Facades\Auth::autentication(['username' => 'value'],  $password ) ) {
		return Auth::getToken();
	}
	`