Skip to content

feat: add bearer token authorization to RampsService payments & quotes#8888

Merged
meltingice1337 merged 5 commits into
mainfrom
feat/TRAM-3502-payments-quotes
Jun 3, 2026
Merged

feat: add bearer token authorization to RampsService payments & quotes#8888
meltingice1337 merged 5 commits into
mainfrom
feat/TRAM-3502-payments-quotes

Conversation

@meltingice1337

@meltingice1337 meltingice1337 commented May 22, 2026

Copy link
Copy Markdown
Contributor

Explanation

The ramps API is gating more endpoints behind bearer-token authentication. PR #8843 introduced the auth plumbing on RampsService (#getRequestHeaders, messenger delegation of AuthenticationController:getBearerToken, runtime dependency on @metamask/profile-sync-controller) and applied it to getBuyWidgetUrl. Two more endpoints — getPaymentMethods and getQuotes — now also require auth upstream, so without a bearer token these calls will start failing and break the Buy flow.

This PR extends the existing auth pattern to those two endpoints:

  • getPaymentMethods awaits #getRequestHeaders() once before dispatching the request through #policy.execute, and passes the resulting Authorization: Bearer <token> header to #fetch.
  • getQuotes does the same.
  • Token retrieval happens outside the retry/circuit-breaker loop (same shape as getBuyWidgetUrl), so a single bearer token is fetched per call and reused across retries. If getBearerToken rejects (wallet locked, signed out), no HTTP request is made.

No new dependencies, no messenger contract change — the AuthenticationController:getBearerToken action is already delegated by consumers as of #8843.

Test updates:

For each of getPaymentMethods and getQuotes, three new tests mirror the coverage added for getBuyWidgetUrl in #8843:

  • sends an Authorization header containing the bearer token — nock reqheaders enforces the header is present on the outgoing request.
  • requests a bearer token exactly once per call — verifies the token is fetched exactly once per call (i.e. outside the retry loop).
  • rejects without making an HTTP call when the bearer token cannot be retrieved — verifies the request short-circuits when AuthenticationController:getBearerToken rejects.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Touches core Buy-flow API calls and auth; failure modes change when the wallet is locked or unsigned-in, but the pattern is already established for getBuyWidgetUrl with no new consumer wiring.

Overview
RampsService.getPaymentMethods and getQuotes now require the same bearer-token auth as getBuyWidgetUrl: each call awaits #getRequestHeaders() (via AuthenticationController:getBearerToken) before #policy.execute, passes Authorization: Bearer … into #fetch, and does not hit the network if token retrieval fails (e.g. locked wallet).

No new messenger contracts or dependencies—consumers already need getBearerToken delegated from v14.0.0. Tests for both methods mirror the buy-widget coverage (header present, token fetched once per call, short-circuit on token failure). Changelog [Unreleased] entry documents the change.

Reviewed by Cursor Bugbot for commit 9a6c86b. Bugbot is set up for automated code reviews on this repo. Configure here.

@meltingice1337 meltingice1337 requested a review from a team as a code owner May 22, 2026 08:05
@meltingice1337 meltingice1337 requested a review from a team as a code owner May 22, 2026 08:08
amitabh94
amitabh94 previously approved these changes Jun 2, 2026
@meltingice1337

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.5.0-preview-1b741b0f9
@metamask-previews/accounts-controller@38.1.2-preview-1b741b0f9
@metamask-previews/address-book-controller@7.1.2-preview-1b741b0f9
@metamask-previews/ai-controllers@0.7.0-preview-1b741b0f9
@metamask-previews/analytics-controller@1.1.0-preview-1b741b0f9
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-1b741b0f9
@metamask-previews/announcement-controller@8.1.0-preview-1b741b0f9
@metamask-previews/app-metadata-controller@2.0.1-preview-1b741b0f9
@metamask-previews/approval-controller@9.0.1-preview-1b741b0f9
@metamask-previews/assets-controller@8.2.0-preview-1b741b0f9
@metamask-previews/assets-controllers@108.3.0-preview-1b741b0f9
@metamask-previews/authenticated-user-storage@2.0.0-preview-1b741b0f9
@metamask-previews/base-controller@9.1.0-preview-1b741b0f9
@metamask-previews/base-data-service@0.1.3-preview-1b741b0f9
@metamask-previews/bridge-controller@73.2.0-preview-1b741b0f9
@metamask-previews/bridge-status-controller@72.0.0-preview-1b741b0f9
@metamask-previews/build-utils@3.0.4-preview-1b741b0f9
@metamask-previews/chain-agnostic-permission@1.6.1-preview-1b741b0f9
@metamask-previews/chomp-api-service@3.1.0-preview-1b741b0f9
@metamask-previews/claims-controller@0.5.2-preview-1b741b0f9
@metamask-previews/client-controller@1.0.1-preview-1b741b0f9
@metamask-previews/compliance-controller@2.1.0-preview-1b741b0f9
@metamask-previews/composable-controller@12.0.1-preview-1b741b0f9
@metamask-previews/config-registry-controller@0.3.2-preview-1b741b0f9
@metamask-previews/connectivity-controller@0.2.0-preview-1b741b0f9
@metamask-previews/controller-utils@12.1.0-preview-1b741b0f9
@metamask-previews/core-backend@6.3.1-preview-1b741b0f9
@metamask-previews/delegation-controller@3.0.1-preview-1b741b0f9
@metamask-previews/earn-controller@12.2.0-preview-1b741b0f9
@metamask-previews/eip-5792-middleware@3.0.4-preview-1b741b0f9
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-1b741b0f9
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-1b741b0f9
@metamask-previews/ens-controller@19.1.3-preview-1b741b0f9
@metamask-previews/eth-block-tracker@15.0.1-preview-1b741b0f9
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-1b741b0f9
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-1b741b0f9
@metamask-previews/foundryup@1.0.1-preview-1b741b0f9
@metamask-previews/gas-fee-controller@26.2.2-preview-1b741b0f9
@metamask-previews/gator-permissions-controller@4.2.0-preview-1b741b0f9
@metamask-previews/geolocation-controller@0.1.3-preview-1b741b0f9
@metamask-previews/json-rpc-engine@10.5.0-preview-1b741b0f9
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-1b741b0f9
@metamask-previews/keyring-controller@26.0.0-preview-1b741b0f9
@metamask-previews/logging-controller@8.0.2-preview-1b741b0f9
@metamask-previews/message-manager@14.1.2-preview-1b741b0f9
@metamask-previews/messenger@1.2.0-preview-1b741b0f9
@metamask-previews/messenger-cli@0.2.0-preview-1b741b0f9
@metamask-previews/money-account-balance-service@1.0.2-preview-1b741b0f9
@metamask-previews/money-account-controller@0.3.1-preview-1b741b0f9
@metamask-previews/money-account-upgrade-controller@2.0.3-preview-1b741b0f9
@metamask-previews/multichain-account-service@10.0.1-preview-1b741b0f9
@metamask-previews/multichain-api-middleware@3.1.2-preview-1b741b0f9
@metamask-previews/multichain-network-controller@3.1.2-preview-1b741b0f9
@metamask-previews/multichain-transactions-controller@7.1.0-preview-1b741b0f9
@metamask-previews/name-controller@9.1.2-preview-1b741b0f9
@metamask-previews/network-controller@32.0.0-preview-1b741b0f9
@metamask-previews/network-enablement-controller@5.2.0-preview-1b741b0f9
@metamask-previews/notification-services-controller@24.1.2-preview-1b741b0f9
@metamask-previews/passkey-controller@2.0.1-preview-1b741b0f9
@metamask-previews/permission-controller@13.1.1-preview-1b741b0f9
@metamask-previews/permission-log-controller@5.1.0-preview-1b741b0f9
@metamask-previews/perps-controller@7.0.0-preview-1b741b0f9
@metamask-previews/phishing-controller@17.2.0-preview-1b741b0f9
@metamask-previews/polling-controller@16.0.6-preview-1b741b0f9
@metamask-previews/preferences-controller@23.1.0-preview-1b741b0f9
@metamask-previews/profile-metrics-controller@3.1.5-preview-1b741b0f9
@metamask-previews/profile-sync-controller@28.1.1-preview-1b741b0f9
@metamask-previews/ramps-controller@14.1.0-preview-1b741b0f9
@metamask-previews/rate-limit-controller@7.0.1-preview-1b741b0f9
@metamask-previews/react-data-query@0.2.1-preview-1b741b0f9
@metamask-previews/remote-feature-flag-controller@4.2.1-preview-1b741b0f9
@metamask-previews/sample-controllers@5.0.1-preview-1b741b0f9
@metamask-previews/seedless-onboarding-controller@10.0.0-preview-1b741b0f9
@metamask-previews/selected-network-controller@26.1.3-preview-1b741b0f9
@metamask-previews/shield-controller@5.1.2-preview-1b741b0f9
@metamask-previews/signature-controller@39.2.3-preview-1b741b0f9
@metamask-previews/snap-account-service@0.2.1-preview-1b741b0f9
@metamask-previews/social-controllers@2.2.1-preview-1b741b0f9
@metamask-previews/storage-service@1.0.1-preview-1b741b0f9
@metamask-previews/subscription-controller@6.1.3-preview-1b741b0f9
@metamask-previews/transaction-controller@66.0.0-preview-1b741b0f9
@metamask-previews/transaction-pay-controller@23.1.0-preview-1b741b0f9
@metamask-previews/user-operation-controller@41.2.3-preview-1b741b0f9
@metamask-previews/wallet@2.0.0-preview-1b741b0f9

…ts-quotes

# Conflicts:
#	packages/ramps-controller/CHANGELOG.md
@meltingice1337 meltingice1337 added this pull request to the merge queue Jun 3, 2026
Merged via the queue into main with commit bd75956 Jun 3, 2026
370 checks passed
@meltingice1337 meltingice1337 deleted the feat/TRAM-3502-payments-quotes branch June 3, 2026 14:46
github-merge-queue Bot pushed a commit that referenced this pull request Jun 11, 2026
#9060)

## Explanation

`RampsService.getPaymentMethods` was recently changed (in #8888, still
unreleased) to send an `Authorization: Bearer <token>` header, sourcing
the token from `AuthenticationController:getBearerToken`. In practice,
the payment-methods was changed to be called before the user signed into
metamask.

Requiring a bearer token there is problematic because
`AuthenticationController.getBearerToken` is not a passive read:

- If the wallet is **locked**, it throws (`getBearerToken - unable to
proceed, wallet is locked`).
- If the wallet is **unlocked but not signed in**, it falls through to
`getAccessToken`, which performs a full SRP **sign-in** (network
round-trip + SIWE/SRP signing) as a side effect.

So fetching a payment-methods catalog could either fail outright or
silently sign the user in — neither of which should happen just to
render a list of payment options.

This PR scopes bearer-token auth back to the endpoints that genuinely
need it. `getPaymentMethods` is now fetched as an unauthenticated
request (matching the existing pattern used by `getGeolocation`,
`getProviders`, etc.), while `getQuotes` and `getBuyWidgetUrl` keep
their `Authorization` headers since they create user-bound
orders/widgets.

Changes:

- **`RampsService.getPaymentMethods`** — removed the
`#getRequestHeaders()` call and now passes no headers to `fetch`. The
private `#getRequestHeaders` helper is unchanged and still used by
`getQuotes` and `getBuyWidgetUrl`.
- **Tests** — replaced the three payment-methods auth tests with
negative assertions (`does not request a bearer token`, `does not send
an Authorization header`) mirroring the existing `getGeolocation`
auth-scope tests. The "rejects when the bearer token cannot be
retrieved" test was removed as no longer applicable.
- **Changelog** — kept the original #8888 entry intact and added a
separate `Changed` entry documenting that `getPaymentMethods` no longer
sends an `Authorization` header.

## References

- Related to #8888 (added the bearer-token auth being scoped down here)

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes when ramps auth runs and could fail if the API still required
a token for payment methods; intended to stop locked-wallet failures and
accidental sign-in from catalog loads.
> 
> **Overview**
> Reverts bearer-token auth on **`RampsService.getPaymentMethods`** so
the regions/payments catalog can load **before** sign-in. The method no
longer calls `#getRequestHeaders()` or sends an `Authorization` header
on `fetch`, aligning it with other public catalog calls (e.g.
geolocation/providers). **`getQuotes`** and **`getBuyWidgetUrl`** still
use authenticated headers.
> 
> Tests now assert payment-methods requests **do not** call
`getBearerToken` and **do not** send `Authorization`, and drop the case
where a missing token blocked the HTTP call. The ramps-controller
changelog records this under **Changed**.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
082a6c3. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Darius Costolas <10818970+meltingice1337@users.noreply.github.com>
@meltingice1337 meltingice1337 mentioned this pull request Jun 12, 2026
4 tasks
pull Bot pushed a commit to dmrazzy/core that referenced this pull request Jun 12, 2026
## Explanation

This is the release PR for `1038.0.0`, generated by
`create-release-branch`. It bumps the monorepo version from `1037.0.0`
to `1038.0.0` and releases a single package:
`@metamask/ramps-controller` `14.1.1` → `14.2.0`. The release moves the
entries that had accumulated under `[Unreleased]` into a new `[14.2.0]`
section in the package's changelog.

`@metamask/ramps-controller@14.2.0` includes the following:

- **Changed** — `RampsService.getQuotes` now sends an `Authorization:
Bearer <token>` header, sourcing the token from
`AuthenticationController:getBearerToken` (already a required messenger
action since `14.0.0`); the call throws if no token is available (e.g.
the wallet is locked or the user is signed out)
([MetaMask#8888](MetaMask#8888)). This is the
notable change driving the version bump: `getQuotes` previously made an
unauthenticated request and now requires a bearer token, so consumers
should review their sign-in state before upgrading.
- **Changed** — Bump `@metamask/controller-utils` from `^12.1.0` to
`^12.2.0` ([MetaMask#9058](MetaMask#9058),
[MetaMask#9083](MetaMask#9083)).

Note on `getPaymentMethods`: within this unreleased window, auth was
added to `getPaymentMethods` (MetaMask#8888) and then removed again (MetaMask#9060) so
that payment methods can be fetched before sign-in. Because that change
was reverted before shipping, it nets to no consumer-facing change and
is intentionally omitted from the changelog per the project's "omit
reverted changes" guideline.

This is a minor release (`14.2.0`). It contains no breaking changes; the
version is bumped to minor — rather than patch — to surface the
`getQuotes` authentication behavior change, which alters how an existing
method makes its request even though the public interface is unchanged.
As part of cutting the release, the in-monorepo consumer
`@metamask/transaction-pay-controller` has its dependency on
`@metamask/ramps-controller` bumped to `^14.2.0`; this is a mechanical
version bump required by the release tooling and does not change
`transaction-pay-controller`'s behavior.

## References

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

Release PR generated by `create-release-branch`; see
`docs/processes/releasing.md`. `@metamask/ramps-controller` was bumped
to a minor (`14.2.0`) rather than a patch in response to review feedback
that the `getQuotes` authentication change is a notable behavior change
to an existing method.

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

---------

Co-authored-by: Darius Costolas <10818970+meltingice1337@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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