Package Data | |
---|---|
Maintainer Username: | khsing |
Maintainer Contact: | khsing.cn@gmail.com (Guixing Bai) |
Package Create Date: | 2017-07-21 |
Package Last Update: | 2018-07-30 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-07 03:02:26 |
Package Statistics | |
---|---|
Total Downloads: | 315 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 3 |
Total Forks: | 1 |
Total Open Issues: | 0 |
This package make OAuth2.0 client credentials able to assign User.
composer require khsing/laravel-restapi
config/app.php
, add it providers
with following linesKhsing\Restapi\OAuth2ServiceProvider::class,
Khsing\Restapi\RestapiServiceProvider::class,
execute php artisan migrate
execute php artisan vendor:publish
Need follow laravel/passport setup
Since Laravel 5.5 LTS, passport would specific route register, can custom in app/Providers/AuthServiceProvider.php
Passport::routes(function ($router) {
$router->forAccessTokens();
$router->forTransientTokens();
});
Support following configure options.
enable_hashids
, boolean, true/falsehashids_salt
, salt of hashids, NEED REPLACE WITH YOURS.hashids_length
, length of hashidshashids_alphabet
, alphabet of hashidsphp artisan passport:client
fill user id, client name and get client secret.
routes/api.php
Route::get('/user', function (Request $request) {
return $request->user();
})->middleware('auth:api');
Now, access /api/user
will get user's infomation.
btw. Postman is great tools. And the most great part is it's free.
composer require dingo/api:2.0.0-alpha1
providers
, Dingo\Api\Provider\LaravelServiceProvider::class,
php artisan vendor:publish
app/Http/Kernel.php
with following lines protected $middlewareGroups = [
...
'api:auth' => [
'auth:api',
'api.auth',
],
]
config/api.php
auth part 'auth' => [
'restapi' => \Khsing\Restapi\DingoAuthServiceProvider::class,
]
routes/api.php
same function$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['middleware' => 'api:auth'], function ($api) {
$api->get('user', function (Request $request) {
return $request->user();
});
});
This library following MIT License, please keep License file.
Guixing: