[GH-ISSUE #19] token定期刷新 #17

Closed
opened 2026-02-27 07:17:24 +03:00 by kerem · 4 comments
Owner

Originally created by @mailbyms on GitHub (Aug 6, 2025).
Original GitHub issue: https://github.com/justlovemaki/AIClient-2-API/issues/19

已经打了镜像,Kiro 转API正常
项目代码里好像找不到定期刷新 Kiro accessToken 和 refreshToken 的处理?

Originally created by @mailbyms on GitHub (Aug 6, 2025). Original GitHub issue: https://github.com/justlovemaki/AIClient-2-API/issues/19 已经打了镜像,Kiro 转API正常 项目代码里好像找不到定期刷新 Kiro accessToken 和 refreshToken 的处理?
kerem closed this issue 2026-02-27 07:17:24 +03:00
Author
Owner

@justlovemaki commented on GitHub (Aug 6, 2025):

没做定时刷新,做的是请求时发现过期,先发起刷新再接着请求。

<!-- gh-comment-id:3158348089 --> @justlovemaki commented on GitHub (Aug 6, 2025): 没做定时刷新,做的是请求时发现过期,先发起刷新再接着请求。
Author
Owner

@mailbyms commented on GitHub (Aug 7, 2025):

场景:
aiclient2api 项目用 docker 部署到服务器,提供接口。
因为 kiro 客户端平时不一定打开,当容器的 refreshToken 都失效后,就获取不了 accessToken

方案:
我让kiro帮我实现一个接口 /refresh-kiro-token,如果 token的expireAt在5分钟内,就触发 kiroService.initializeAuth(true); // Force refresh with forceRefresh = true
代码在这里,供参考 github.com/justlovemaki/AIClient-2-API@c814035487
同时在 docker-compose.yml 里定义 health-check 每5分钟调用一次 /refresh-kiro-token ,就能让 kiro 的 accessToken 一直有效
完整的 docker-compose.yml

version: "3"
services:
    aicli2api:
        ports:
            - 3001:3000
        environment:
            - ARGS=--api-key 123456 --host 0.0.0.0
        container_name: aiclient2api
        image: mailbyms/aiclient2api
        volumes:
            - ./config.json:/app/config.json
            - ./oauth_creds.json:/home/nextjs/.gemini/oauth_creds.json
            - ./kiro-auth-token.json:/home/nextjs/.aws/sso/cache/kiro-auth-token.json
        healthcheck:
          test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:3000/refresh-kiro-token"]
          interval: 300s  # 每 5 分钟检查一次
          timeout: 30s    # 每次检查的超时时间为 30 秒
          retries: 3      # 如果失败,重试 3 次
          start_period: 5s  # 容器启动后 5 秒开始检查
<!-- gh-comment-id:3162291645 --> @mailbyms commented on GitHub (Aug 7, 2025): 场景: aiclient2api 项目用 docker 部署到服务器,提供接口。 因为 kiro 客户端平时不一定打开,当容器的 refreshToken 都失效后,就获取不了 accessToken 方案: 我让kiro帮我实现一个接口 /refresh-kiro-token,如果 token的expireAt在5分钟内,就触发 kiroService.initializeAuth(true); // Force refresh with forceRefresh = true 代码在这里,供参考 https://github.com/justlovemaki/AIClient-2-API/commit/c81403548758f950631cfafb43b0622e20e5ec0d 同时在 docker-compose.yml 里定义 health-check 每5分钟调用一次 /refresh-kiro-token ,就能让 kiro 的 accessToken 一直有效 完整的 docker-compose.yml ``` version: "3" services: aicli2api: ports: - 3001:3000 environment: - ARGS=--api-key 123456 --host 0.0.0.0 container_name: aiclient2api image: mailbyms/aiclient2api volumes: - ./config.json:/app/config.json - ./oauth_creds.json:/home/nextjs/.gemini/oauth_creds.json - ./kiro-auth-token.json:/home/nextjs/.aws/sso/cache/kiro-auth-token.json healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:3000/refresh-kiro-token"] interval: 300s # 每 5 分钟检查一次 timeout: 30s # 每次检查的超时时间为 30 秒 retries: 3 # 如果失败,重试 3 次 start_period: 5s # 容器启动后 5 秒开始检查 ```
Author
Owner

@justlovemaki commented on GitHub (Aug 7, 2025):

场景: aiclient2api 项目用 docker 部署到服务器,提供接口。 因为 kiro 客户端平时不一定打开,当容器的 refreshToken 都失效后,就获取不了 accessToken

方案: 我让kiro帮我实现一个接口 /refresh-kiro-token,如果 token的expireAt在5分钟内,就触发 kiroService.initializeAuth(true); // Force refresh with forceRefresh = true 代码在这里,供参考 c814035 同时在 docker-compose.yml 里定义 health-check 每5分钟调用一次 /refresh-kiro-token ,就能让 kiro 的 accessToken 一直有效 完整的 docker-compose.yml

version: "3"
services:
    aicli2api:
        ports:
            - 3001:3000
        environment:
            - ARGS=--api-key 123456 --host 0.0.0.0
        container_name: aiclient2api
        image: mailbyms/aiclient2api
        volumes:
            - ./config.json:/app/config.json
            - ./oauth_creds.json:/home/nextjs/.gemini/oauth_creds.json
            - ./kiro-auth-token.json:/home/nextjs/.aws/sso/cache/kiro-auth-token.json
        healthcheck:
          test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:3000/refresh-kiro-token"]
          interval: 300s  # 每 5 分钟检查一次
          timeout: 30s    # 每次检查的超时时间为 30 秒
          retries: 3      # 如果失败,重试 3 次
          start_period: 5s  # 容器启动后 5 秒开始检查

不错,提供了思路

<!-- gh-comment-id:3162400914 --> @justlovemaki commented on GitHub (Aug 7, 2025): > 场景: aiclient2api 项目用 docker 部署到服务器,提供接口。 因为 kiro 客户端平时不一定打开,当容器的 refreshToken 都失效后,就获取不了 accessToken > > 方案: 我让kiro帮我实现一个接口 /refresh-kiro-token,如果 token的expireAt在5分钟内,就触发 kiroService.initializeAuth(true); // Force refresh with forceRefresh = true 代码在这里,供参考 [c814035](https://github.com/justlovemaki/AIClient-2-API/commit/c81403548758f950631cfafb43b0622e20e5ec0d) 同时在 docker-compose.yml 里定义 health-check 每5分钟调用一次 /refresh-kiro-token ,就能让 kiro 的 accessToken 一直有效 完整的 docker-compose.yml > > ``` > version: "3" > services: > aicli2api: > ports: > - 3001:3000 > environment: > - ARGS=--api-key 123456 --host 0.0.0.0 > container_name: aiclient2api > image: mailbyms/aiclient2api > volumes: > - ./config.json:/app/config.json > - ./oauth_creds.json:/home/nextjs/.gemini/oauth_creds.json > - ./kiro-auth-token.json:/home/nextjs/.aws/sso/cache/kiro-auth-token.json > healthcheck: > test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:3000/refresh-kiro-token"] > interval: 300s # 每 5 分钟检查一次 > timeout: 30s # 每次检查的超时时间为 30 秒 > retries: 3 # 如果失败,重试 3 次 > start_period: 5s # 容器启动后 5 秒开始检查 > ``` 不错,提供了思路
Author
Owner

@justlovemaki commented on GitHub (Aug 7, 2025):

最新版已包含定时刷新token的逻辑

<!-- gh-comment-id:3163975543 --> @justlovemaki commented on GitHub (Aug 7, 2025): 最新版已包含定时刷新token的逻辑
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/AIClient-2-API-justlovemaki#17
No description provided.