perf: openapi token有效期配置

This commit is contained in:
2025-07-15 14:45:16 +08:00
parent cdba5a97b7
commit c9f35dc309
3 changed files with 10 additions and 2 deletions

View File

@@ -42,6 +42,8 @@ MAX_ATTACHMENT_SIZE = 100mb # 附件上传最大限制
# 开放API
[OPENAPI]
ACCESS_TOKEN_LIFETIME = 3600 # 访问令牌有效期
REFRESH_TOKEN_LIFETIME = 1209600 # 刷新令牌有效期
RESOURCE_IMAGES_DOMAIN = http://local.orico.com; # 图片资源服务器地址
RESOURCE_VIDEOS_DOMAIN = http://local.orico.com; # 视频资源服务器地址

View File

@@ -25,7 +25,10 @@ class Authorize
$server = request()->server();
$request = new Request([], $post, [], [], [], $server);
$storage = new OAuthStorage;
$oauth = new OAuth2($storage);
$oauth = new OAuth2($storage, [
'access_token_lifetime' => env('OPENAPI.ACCESS_TOKEN_LIFETIME', 3600),
'refresh_token_lifetime' => env('OPENAPI.REFRESH_TOKEN_LIFETIME', 1209600),
]);
$token = $oauth->grantAccessToken($request);
return success('success', json_decode($token->getContent(), true));
} catch (OAuth2ServerException $e) {

View File

@@ -19,7 +19,10 @@ class Auth
public function handle($request, \Closure $next)
{
try {
$oauth = new OAuth2(new OAuthStorage);
$oauth = new OAuth2(new OAuthStorage, [
'access_token_lifetime' => env('OPENAPI.ACCESS_TOKEN_LIFETIME', 3600),
'refresh_token_lifetime' => env('OPENAPI.REFRESH_TOKEN_LIFETIME', 1209600),
]);
$token = $oauth->getBearerToken();
$oauth->verifyAccessToken($token);
} catch (OAuth2ServerException $e) {