PHP code example of 96qbhy / laravel-api-auth
1. Go to this page and download the library: Download 96qbhy/laravel-api-auth library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
96qbhy / laravel-api-auth example snippets
Qbhy\LaravelApiAuth\ServiceProvider::class,
php artisan vendor:publish --provider="Qbhy\LaravelApiAuth\ServiceProvider"
protected $routeMiddleware = [
'api_auth' => \Qbhy\LaravelApiAuth\Middleware::class,
// other ...
];
php artisan api_auth
'roles' => [
'{access_key}' => [
'name' => '{role_name}', // 角色名字,例如 android
'secret_key' => '{secret_key}',
],
],
/**
* User: 96qbhy
* Date: 2018/4/16
* Time: 下午3:22
*/
namespace Qbhy\LaravelApiAuth\Signatures;
class Md5 implements SignatureInterface
{
public static function sign(string $string, string $secret): string
{
return md5($string . $secret);
}
public static function check(string $string, string $secret, string $signature): bool
{
return static::sign($string, $secret) === $signature;
}
}
Route::get('api/example', function(Request $request){
// $request->get('client_role');
// todo...
})->middleware(['api_auth']);
\\ or
Route::group(['middleware'=>'api_auth'], function(){
// routes...
});