[接口]鉴权authToken用户登录login-注册register-退出logout, 并将用户信息保存到redis中
This commit is contained in:
35
server/app/api/controller/AuthTokenController.php
Normal file
35
server/app/api/controller/AuthTokenController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use Tinywan\Jwt\JwtToken;
|
||||
use plugin\saiadmin\basic\OpenController;
|
||||
|
||||
/**
|
||||
* API 鉴权 Token 接口
|
||||
* 后续所有 /api 接口调用均需在请求头携带此接口返回的 auth-token
|
||||
*/
|
||||
class AuthTokenController extends OpenController
|
||||
{
|
||||
/**
|
||||
* 获取 auth-token
|
||||
* GET 或 POST /api/authToken
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$exp = config('api.auth_token_exp', 86400);
|
||||
$tokenResult = JwtToken::generateToken([
|
||||
'id' => 0,
|
||||
'plat' => 'api',
|
||||
'access_exp' => $exp,
|
||||
]);
|
||||
|
||||
return $this->success([
|
||||
'auth-token' => $tokenResult['access_token'],
|
||||
'expires_in' => $tokenResult['expires_in'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user