File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "permissions" : {
33 "allow" : [
4- " Bash(cargo check:*)"
4+ " Bash(cargo check:*)" ,
5+ " Bash(grep:*)" ,
6+ " WebSearch" ,
7+ " Bash(pnpm add:*)" ,
8+ " Bash(npm run build:*)"
59 ]
610 }
711}
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ HC_API_BASE=http://localhost:8080
88HC_JWT_SECRET = please-set-a-strong-random-secret-32chars
99HC_JWT_ISSUER = hypercraft-api
1010HC_JWT_AUDIENCE = hypercraft-clients
11+ # JWT Token 有效期(秒)
12+ # HC_ACCESS_TOKEN_TTL=21600 # Access Token 有效期(默认 6 小时)
13+ # HC_REFRESH_TOKEN_TTL=604800 # Refresh Token 有效期(默认 7 天)
1114# 逗号分隔命令名(仅文件名)
1215HC_ALLOWED_COMMANDS = java.exe,node.exe
1316# 分号分隔绝对路径前缀
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use crate::error::{Result, ServiceError};
66use chrono:: Utc ;
77use serde_json;
88use std:: collections:: HashMap ;
9+ use std:: env;
910use std:: fs;
1011use std:: path:: { Path , PathBuf } ;
1112use tracing:: { info, instrument} ;
@@ -37,13 +38,24 @@ pub struct UserManager {
3738impl UserManager {
3839 /// 创建新的用户管理器
3940 pub fn new < P : AsRef < Path > > ( data_dir : P , jwt_secret : String ) -> Self {
41+ // 从环境变量读取 TTL,如果未设置则使用默认值
42+ let access_token_ttl = env:: var ( "HC_ACCESS_TOKEN_TTL" )
43+ . ok ( )
44+ . and_then ( |s| s. parse ( ) . ok ( ) )
45+ . unwrap_or ( 6 * 60 * 60 ) ; // 默认 6 小时
46+
47+ let refresh_token_ttl = env:: var ( "HC_REFRESH_TOKEN_TTL" )
48+ . ok ( )
49+ . and_then ( |s| s. parse ( ) . ok ( ) )
50+ . unwrap_or ( 7 * 24 * 3600 ) ; // 默认 7 天
51+
4052 Self {
4153 data_dir : data_dir. as_ref ( ) . to_path_buf ( ) ,
4254 jwt_secret,
4355 jwt_issuer : DEFAULT_JWT_ISSUER . to_string ( ) ,
4456 jwt_audience : DEFAULT_JWT_AUDIENCE . to_string ( ) ,
45- access_token_ttl : 15 * 60 , // 15 分钟
46- refresh_token_ttl : 7 * 24 * 3600 , // 7 天
57+ access_token_ttl,
58+ refresh_token_ttl,
4759 }
4860 }
4961
You can’t perform that action at this time.
0 commit comments