feat: integrate AuthenticationController for bearer token handling in…#8843
Open
meltingice1337 wants to merge 2 commits into
Open
feat: integrate AuthenticationController for bearer token handling in…#8843meltingice1337 wants to merge 2 commits into
meltingice1337 wants to merge 2 commits into
Conversation
fb101e4 to
47ab3ba
Compare
47ab3ba to
30578d8
Compare
Contributor
Author
|
@metamaskbot publish-previews |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
amitabh94
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
RampsService.getBuyWidgetUrlpreviously issued unauthenticated requests to the ramps API (/providers/<provider>/buy-widget). The upstream API is being gated behind authentication, so without a bearer token the call will start to fail and break the Buy flow for every consumer (mobile, extension).This PR makes
getBuyWidgetUrlauthenticated by sourcing a bearer token fromAuthenticationControllervia the messenger and attaching it as anAuthorization: Bearer <token>header on the outgoing request.How it works:
RampsService.#getRequestHeaderscalls the messenger actionAuthenticationController:getBearerTokenand returns theAuthorizationheader. It is awaited once pergetBuyWidgetUrlinvocation (verified by a new test) before the request is dispatched through the existing#policy.executewrapper, so token retrieval happens outside the retry/circuit-breaker loop. If the token call rejects (e.g. wallet is locked, user signed out), the rejection propagates and no HTTP call is made — also covered by a new test.RampsServiceMessenger'sAllowedActionsis widened fromnevertoAuthenticationController.AuthenticationControllerGetBearerTokenAction. This is a breaking change to the messenger contract: consumers must delegate theAuthenticationController:getBearerTokenaction into the ramps messenger before callinggetBuyWidgetUrl.getBuyWidgetUrlis authenticated in this PR. Other endpoints (e.g.getGeolocation) remain unauthenticated and explicitly do not request a bearer token; this is locked in by tests that assertgetBearerTokenis not called and that noAuthorizationheader is sent for those endpoints.Dependency added:
@metamask/profile-sync-controller@^28.1.0is added as a runtime dependency solely for itsAuthenticationControllertype export (theAuthenticationControllerGetBearerTokenActionaction type). It is not instantiated byramps-controller; the implementing controller lives in the consuming app and is wired up via the messenger.Demo:
auth_demo.mp4
Test updates:
getBuyWidgetUrlnow assert theAuthorization: Bearer mock-bearer-tokenheader is present on the nock interceptor.getBearerTokenshort-circuits before any HTTP request; and the scope assertion thatgetGeolocationremains unauthenticated.getRootMessenger/getServicetest helpers now delegate theAuthenticationController:getBearerTokenaction and expose amockGetBearerTokenjest mock so individual tests can override the resolution behavior.References
Checklist
Note
Medium Risk
Medium risk due to a breaking messenger contract change requiring consumers to delegate
AuthenticationController:getBearerToken, and because it changes howgetBuyWidgetUrlperforms network requests by adding auth headers and failing early when tokens are unavailable.Overview
RampsService.getBuyWidgetUrlnow authenticates buy-widget requests by retrieving a bearer token via the messenger actionAuthenticationController:getBearerTokenand sendingAuthorization: Bearer <token>on the HTTP call.This widens
RampsServiceMessengerallowed actions (a breaking change for consumers that must delegate/register the new action), adds@metamask/profile-sync-controlleras a runtime dependency for the action type, updates TS project references, and extends tests to assert auth header behavior, token fetch call counts, and that unrelated endpoints (e.g.getGeolocation) remain unauthenticated.Reviewed by Cursor Bugbot for commit bdad742. Bugbot is set up for automated code reviews on this repo. Configure here.