PHP code example of harryhoga / laravel-api-auth
1. Go to this page and download the library: Download harryhoga/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/ */
harryhoga / laravel-api-auth example snippets
Hoga\LaravelApiAuth\ServiceProvider::class,
php artisan vendor:publish --provider="Hoga\LaravelApiAuth\ServiceProvider"
protected $routeMiddleware = [
'apiauth' => \Hoga\LaravelApiAuth\Middleware::class,
// other ...
];
php artisan apiauth
'roles' => [
'{access_key}' => [
'name' => '{role_name}', // 角色名字,例如 android
'secret_key' => '{secret_key}',
],
],
/**
* User: hoga
* Date: 2022/8/16
* Time: 下午3:22
*/
namespace Hoga\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(['apiauth']);
\\ or
Route::group(['middleware'=>'apiauth'], function(){
// routes...
});