Skip to content

fix(sdk-api): route authenticate() to v2 login - #9716

Merged
pranishnepal merged 2 commits into
masterfrom
WCN-2652
Sep 11, 2026
Merged

fix(sdk-api): route authenticate() to v2 login#9716
pranishnepal merged 2 commits into
masterfrom
WCN-2652

Conversation

@pranishnepal

@pranishnepal pranishnepal commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

What

/api/auth/v1/session is behind a Cloudflare managed challenge that HTTP/Node clients cannot complete, breaking the documented SDK login flow. Route bitgo.authenticate() to /api/v2/user/login instead.

Also:

  • Make authenticateWithAccessToken async and await the HMAC strategy setToken() so the token is registered before the caller issues any subsequent signed request (closes a race for async strategies like WebCryptoHmacStrategy). Await at both call sites.

Ticket: WCN-2652


Note to Reviewers:

Commit 1 - the change mentioned above
Commit 2 - migration of the examples

Testing

  • Unit Tests
  • E2E Testing - login and access token creation
[LOGIN] authenticate() against env=staging ...
[LOGIN] target endpoint expected: https://app.bitgo-staging.com/api/v2/user/login

[LOGIN] SUCCESS
[LOGIN] user = hi@hi.com
[LOGIN] access_token present = true
[LOGIN] access_token = v2x784abeb.............
(node:8377) [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.
(Use `node --trace-deprecation ...` to show where the warning was created)
[LOGIN] /user/me returned user = "hi@hi.com"

@linear-code

linear-code Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

WCN-2652

@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

⚠️ Unit tests are failing on Node 26.x (Current release line, non-blocking). This is not an LTS version yet, so it does not block merge, but it signals an incompatibility to fix before Node 26.x becomes LTS.

View run

@pranishnepal
pranishnepal marked this pull request as ready for review September 10, 2026 20:26
@pranishnepal
pranishnepal requested review from a team as code owners September 10, 2026 20:26
Comment thread modules/sdk-api/src/bitgoAPI.ts

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change looks good, but we need to be explicit that the signature change is a breaking change.

/api/auth/v1/session is behind a Cloudflare managed challenge that
HTTP/Node clients cannot complete, breaking the documented SDK login
flow. Route bitgo.authenticate() to /api/v2/user/login instead.

Also:
- Make authenticateWithAccessToken async and await the HMAC
  strategy setToken() so the token is registered before the caller
  issues any subsequent signed request (closes a race for async
  strategies like WebCryptoHmacStrategy). Await at both callers
  (fetchEncryptedPrivKeys, upgrade-wallet-encryption).
- Update unit test nocks to the v2 login endpoint; add a test for
  the ECDH-encrypted-token path; keep extensible passthrough.

BREAKING CHANGE: authenticateWithAccessToken now returns
Promise<void> instead of void. Callers that relied on synchronous
completion must await it; login now routes through /api/v2/user/login.

TICKET: WCN-2652
Migrate all example callers to await the async
authenticateWithAccessToken API before issuing signed requests.

Move authentication out of synchronous CommonJS config modules and into
their async consumers, while exposing the access token through the
config objects. Authenticate the same SDK or BitGo client used by each
consumer.

Also update Promise coroutine examples to yield authentication and
preserve synchronous config exports.

Ticket: WCN-2652

TICKET: WCN-2652
@pranishnepal
pranishnepal requested a review from a team as a code owner September 11, 2026 13:28
@pranishnepal
pranishnepal merged commit 79a4b2e into master Sep 11, 2026
26 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.

5 participants