Skip to content

feat(baidu-netdisk): refresh and rotate single-use tokens - #1156

Merged
Xuanwo merged 7 commits into
apache:mainfrom
suyanhanx:baidu-netdisk-refresh
Dec 2, 2026
Merged

Xuanwo merged 7 commits into
apache:mainfrom
suyanhanx:baidu-netdisk-refresh

Conversation

@suyanhanx

@suyanhanx suyanhanx commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Add Baidu Netdisk refresh-token exchange to Reqsign. A host calls exchange_refresh_token, saves the replacement refresh token, then checks response.credential for the access token and its expiry. Even if the access token or expiry is unusable, the host receives the replacement.

For on-demand renewal with Signer, RefreshCredentialProvider takes a required save callback. Provider clones serialize exchanges and saves. A failed save leaves the replacement pending so the next call retries persistence before exchanging another token. Hosts must serialize use of each authorization across processes. Losing the response before saving the replacement can require reauthorization.

Verification

  • All ten native Baidu Netdisk integration tests and the crate doctest passed offline. The three rotation tests cover resuming from a saved token after restart, receiving the replacement when the access credential is unusable, and retrying a failed save before another exchange.
  • An earlier revision was exercised against the live Baidu endpoint. It returned a rotated refresh token and a 2,592,000-second access-token lifetime. A signed read-only uinfo request returned HTTP 200 with errno = 0.

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI-generated maintenance review of ff846503.

Baidu consumes the current refresh_token on exchange. RefreshCredentialProvider keeps the replacement in private memory, so even after a successful refresh and a clean shutdown, the host has no token it can use for the next refresh. Baidu OAuth documentation · OpenDAL persistence contract

Could you expose a Baidu-specific exchange that accepts the current refresh token and returns the replacement, together with the access token and expiry when usable? The host can then persist the replacement and rebuild its OpenDAL operator with the new access token. If Baidu returns a valid replacement alongside a missing or unusable access_token or expires_in, the result or error still needs to give the host that replacement. The old token has already been spent.

The in-process provider can keep automatic renewal if it hands every rotation back to the host, through a return value or a required callback. Please document that callers must serialize exchanges for each authorization and may need to reauthorize if the response is lost before the replacement is saved.

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI-generated maintenance review of 269c8a5d.

The seven native tests and the WASM test in reqsign-baidu-netdisk never call RefreshCredentialProvider. A change that drops the replacement refresh token could pass all eight tests. Previous review

Could you add mock-response tests through the public exchange API? On success, have the caller save the replacement, recreate its state, and use the saved token for the next exchange. Also check that the caller receives the replacement when the same response contains an unusable access_token or expires_in. Baidu has already consumed the old refresh token in both cases.

@suyanhanx

Copy link
Copy Markdown
Member Author

Addressed both reviews in 5600440. The host can now call exchange_refresh_token and save response.refresh_token before checking response.credential. The automatic provider also requires a save callback. A failed save is retried with the same replacement on the next call.

The public API tests exercise a second exchange after reloading the saved token from disk, and verify that a missing or invalid access token or expiry still yields the replacement. A provider test covers a failed save followed by a retry without a second HTTP exchange. These cases passed with mock responses.

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI-generated maintenance review of d4b48c9f.

The latest commit removes the three tests that exercised refresh-token rotation. Production code is unchanged. Running cargo test --offline -p reqsign-baidu-netdisk --no-fail-fast still passes all seven native tests, but none calls the refresh API. Baidu consumes the old token on exchange, so losing its replacement can force the caller to reauthorize.

Could you restore the tests from 5600440a or keep equivalent offline assertions through the public API before merge?

  1. The host can save the replacement, reload it after restart, and use it for the next exchange.
  2. The host receives the replacement even when the access token or expiry is unusable.
  3. After a save fails, a provider clone retries saving the same replacement before attempting another exchange.

@suyanhanx
suyanhanx marked this pull request as ready for review December 2, 2026 15:52
@Xuanwo
Xuanwo merged commit c7b7e5b into apache:main Dec 2, 2026
67 checks passed
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.

2 participants