Skip to content

fix: 修复 authen v1 token 接口请求格式 (#196)#197

Merged
foxzool merged 4 commits into
mainfrom
codex/fix-authen-v1-token-196
Jun 11, 2026
Merged

fix: 修复 authen v1 token 接口请求格式 (#196)#197
foxzool merged 4 commits into
mainfrom
codex/fix-authen-v1-token-196

Conversation

@foxzool

@foxzool foxzool commented Jun 11, 2026

Copy link
Copy Markdown
Owner

摘要

  • 修复 authen v1 四个 token 接口的请求/响应形态兼容,解决 OIDC 与 v1 access_token 的响应空值问题(issue authen_service的oidc以及正常的获取access_token的方法错误 #196)。
  • 更新请求体为 JSON 格式,补齐默认 grant_type,并在接口端使用 access_token 鉴权。
  • 在核心层新增 ApiRequest 的 per-request token 类型覆盖能力:AccessTokenType::App。
  • 抽出 token 相关模型并补齐响应别名处理。
  • 增加四条 wiremock 回归测试(v1 access/refresh,OIDC access/refresh)覆盖请求 body、Authorization、response 映射。

验证

  • cargo fmt --all
  • cargo test -p openlark-auth
  • cargo test -p openlark-core
  • cargo clippy -p openlark-core -p openlark-auth --all-targets -- -D warnings
  • git diff --check

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 46100261ac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

impl ApiResponseTrait for UserAccessTokenV1ResponseData {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
ResponseFormat::Flatten

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid logging token responses through Flatten

When these token APIs use ResponseFormat::Flatten, they are handled by handle_flatten_response, which currently emits debug!("Raw response: {response_text}") before parsing. For successful access-token/refresh-token calls, that raw JSON contains access_token and often refresh_token, so enabling debug logs leaks live credentials; the standard Data path explicitly avoids raw response logging for this reason. Please either remove/redact the flatten raw-response log or avoid sending credential-bearing responses through that handler.

Useful? React with 👍 / 👎.

ApiRequest::post(api_endpoint.path()).body(serde_json::to_value(&request_body)?);
ApiRequest::post(api_endpoint.path())
.body(serde_json::to_value(&request_body)?)
.with_supported_access_token_types(vec![AccessTokenType::App]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce app-token selection for app-only token calls

When enable_token_cache(false) is used, determine_token_type ignores this supported-token override and picks user_access_token before app_access_token. Since this endpoint is now marked app-only, a reused RequestOption containing a user token (even alongside an app token) sends Authorization: Bearer <user> to an app-auth endpoint and fails; please either reject unsupported explicit tokens or force the App token for these calls.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c33d57fbd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
}

return AccessTokenType::None;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not downgrade app-only requests to unauthenticated

When token cache is disabled and a request now constrains tokens to vec![AccessTokenType::App], this new fallback returns None if the caller omits app_access_token or only passes an unsupported user/tenant token. validate explicitly allows AccessTokenType::None, so the four newly app-only authen token calls proceed without any Authorization header instead of failing locally for the missing app token; the new early return here is the fresh evidence beyond the earlier user-vs-app selection issue. Please keep the requested token type (so AuthHandler reports the missing app token) or reject unsupported explicit tokens rather than silently sending an unauthenticated request.

Useful? React with 👍 / 👎.

@foxzool foxzool merged commit f6311b8 into main Jun 11, 2026
120 checks passed
@foxzool foxzool deleted the codex/fix-authen-v1-token-196 branch June 11, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant