bor3y/apitemplate
Composer 安装命令:
composer require bor3y/apitemplate
包简介
generate api code base
关键字:
README 文档
README
Make life easier
Installation
- install jwt for laravel Via Composer
$ composer require tymon/jwt-auth 1.0.0-rc.3
- Configure Auth guard change this lines in "config/auth.php"
guards' => [ 'api' => [ 'driver' => 'jwt', 'provider' => 'users', ],
- add to auth config "config/auth.php"
/* |-------------------------------------------------------------------------- | API Client Credentials |-------------------------------------------------------------------------- | */ 'client_id' => env('CLIENT_ID', ''), 'client_secret' => env('CLIENT_SECRET'. ''),
- Update your User model to implements "Tymon\JWTAuth\Contracts\JWTSubject"
/** * Get the identifier that will be stored in the subject claim of the JWT. * * @return mixed */ public function getJWTIdentifier() { return $this->getKey(); } /** * Return a key value array, containing any custom claims to be added to the JWT. * * @return array */ public function getJWTCustomClaims() { return []; }
- install our package Via Composer
$ composer require --dev bor3y/apitemplate
- publish package using command
$ php artisan auth:api:publish
- Add namespace to apiRoutes in "app/Providers/RouteServiceProvider.php"
protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace . '\API') ->as('api.') ->group(base_path('routes/api.php')); }
- Add basic authentication routes
Route::group(['prefix' => 'auth', 'namespace' => 'Auth'], function(){ Route::group(['middleware' => 'auth.api.public'], function() { Route::post('/register', 'AuthController@register')->name('register'); Route::post('/login', 'AuthController@login')->name('login'); Route::group(['prefix' => 'password', 'as' => 'password.'], function(){ Route::post('/forget', 'PasswordController@sendResetLinkEmail')->name('forget'); }); Route::post('/token/refresh', 'AuthController@refreshToken')->name('refreshToken'); }); Route::group(['middleware' => 'auth:api'], function(){ Route::get('/user', ['as' => 'user', 'uses' => 'AuthController@user']); Route::post('/logout', ['as' => 'logout', 'uses' => 'AuthController@logout']); Route::post('/password/change', 'PasswordController@changePassword')->name('password.change'); }); });
- add to kernel routesMiddleware "app/Http/Kernel.php"
'auth.api.public' => \App\Http\Middleware\AuthorizePublicApiRequests::class
We are done
License
license. Please see the license file for more information.
统计信息
- 总下载量: 52
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-17