feat: [SDK-5234] set Authorization: Bearer at the fetch chokepoint - #1502
Merged
Merged
Conversation
RequestMetadata carries the token as `jwt`. The base API functions take a RequestOptions object with `headers` and `jwt`, and `call()` is the only place that writes the Authorization header. The 11 user-scoped endpoints in requests/api.ts pass the token through one requestOptions helper. The dead `jwtHeader` spread sites are gone; 4 of them passed the header object in the body slot of GET and DELETE. The MSW getHandler helper records request headers in requestHeadersFn so tests can assert the bearer. Tests cover every forwarding endpoint with and without a token, the subscription id header next to the bearer, and a GET with a token that sends no body. The page bundle shrinks by 10 B gzipped to 44.27 kB. The service worker bundle grows by 2 B to 12.53 kB. Both limits move to the measured size.
sherwinski
added this pull request to stack #1507
September 22, 2026 02:31
fadi-george
approved these changes
Sep 22, 2026
Contributor
|
I assume youll update updateSubscriptionById & updateSubscriptionById later @sherwinski ? |
Contributor
Author
Yes, in #1506 |
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.
Description
1 Line Summary
call()insrc/shared/api/base.tsis the one place that writesAuthorization: Bearer, andRequestMetadatacarries the token asjwt.Details
Second pull request of the M3 stack for Identity Verification for Web SDK. Stacked on #1501 (SDK-5308).
Before this change the token had 2 half-built paths and neither worked:
RequestMetadata.jwtHeaderwas never set, andAPIHeaders.Authorizationwas type-only. Now there is 1 mechanism.src/shared/api/base.tsRequestOptions { headers?: APIHeaders; jwt?: string }.get,post,put,patchanddeletetake(action, data?, options?).call()appendsAuthorization: Bearer <jwt>whenoptions.jwtis set. No other code writes that header.Log._erroron a fetch timeout prints the URL only), so there is nothing to redact. The token stays out of theheadersobject on purpose so a future log line cannot print it by accident.src/core/types/api.tsRequestMetadata.jwtHeader?: APIHeadersbecomesjwt?: string.src/core/requests/api.tsrequestOptions(requestMetadata)helper builds{ headers, jwt }. The 11 user-scoped endpoints pass it.updateSubscriptionByIdanddeleteSubscriptionByIdare unchanged; SDK-5237 decides those 2.jwtHeaderin thedataslot ofgetanddelete(getUserByAlias,deleteUserByAlias,getUserIdentity,deleteAlias). Had a token ever been set, a GET would have gone out with a body. The new tests pin that a GET with a token sends no body.requestOptionssetsOneSignal-Subscription-Idon every endpoint whensubscriptionIdis in the metadata. Before, onlycreateNewUserandupdateUserByAliasdid. No executor passessubscriptionIdtoday, so no request changes.src/shared/models/APIHeaders.tsAuthorization?: stringis gone. The index signature narrows fromanytostring, which is whatHeaders.appendtakes.Test helper.
getHandlerin__test__/support/helpers/requests.tsrecords(headers, url)for every request in the exportedrequestHeadersFn, so tests can assert the bearer. The existing body callbacks are unchanged, so notoHaveBeenCalledWithassertion moves.Bundle size.
page.es6.jsshrinks by 10 B gzipped to 44.27 kB.sw.jssharesbase.tsand grows by 2 B gzipped to 12.53 kB, 2 B over its limit. Both limits move to the measured size (44.27 kB and 12.54 kB).Systems Affected
Validation
Tests
Info
New
src/core/requests/api.test.ts(22 tests), the web mirror of AndroidHttpClientTests.kt:263-291:Authorization: Bearerheader is present whenjwtis given, and absent when it is not. A POST with a token resolvesok.createNewUser.vp check,vp test(706 tests), andvp run build:prodpass.Checklist
Programming Checklist
Interfaces:
Functions:
Typescript:
Other:
elem of arraysyntax. PreferforEachor usemapcontextif possible. Instead, we can pass it to function/constructor so that we don't callOneSignal.contextScreenshots
Info
Not needed. No user-visible change.
Checklist
Related Tickets