Repository navigation
Conversation
So that a redirected request can be built asynchronously, for example when it needs a newly signed header. Co-Authored-By: Claude Opus 5.5 <[email protected]>
XdProxyTransport dropped the options given to httpRequest. It now passes them through, honors followRedirect: false, and wraps the redirected request built by a given followRedirect function for the proxy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Salesforce will require PKCE, refresh token rotation and a proof-of-possession control such as DPoP for installing connected apps and external client apps into other orgs. Add a dpop option to the OAuth2 config that takes a signer, and a DPoP class that creates the proofs, so that tokens are bound to the key and API requests are sent with DPoP proofs. SOAP APIs (SOAP, Metadata, Apex SOAP) get the proof in the DpopProofHeader SOAP header. Bulk 1 and Streaming requests fail before they are sent, since they do not accept DPoP tokens. Salesforce gives the nonce only at the token endpoint, and the nonce belongs to the session of the access token. The token methods return it as extra.proofNonce, and a connection keeps it as proofNonce, which can be saved and passed with the access token, so that a connection created later can call APIs without a refresh. Refs #1867 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Browsers do not let scripts read a redirect response, so a request through the AJAX proxy cannot follow a redirect in the browser. When the caller builds the redirected request itself with a followRedirect function, as DPoP requests do, ask the proxy to report redirects in headers (SalesforceProxy-Redirect: report), and turn a reported redirect back into the redirect response. In the browser, a failed fetch, including that of a redirected request, now ends the request with the error instead of leaving it pending. Refs jsforce/jsforce-ajax-proxy#18 Co-Authored-By: Claude Opus 5.5 <[email protected]>
jsforce-ajax-proxy 2.1.0 allows the DPoP request header and reports redirects in headers, which DPoP requests from the browser through the proxy need. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bulk 1 cannot be called with a DPoP token. Bulk._request() now fails before creating the request, as Streaming does in _createClient(), so HttpApi does not need to know about APIs that do not support DPoP. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the report A 200 response with SalesforceProxy-Redirect-* headers was turned into a redirect for any request, also without the proxy. It is now restored only when the request was sent with SalesforceProxy-Redirect: report. Co-Authored-By: Claude Opus 5.5 <[email protected]>
SOAP.beforeSend() now builds the envelope and computes its length for every attempt, so HttpApi no longer removes content-length of SOAP requests after a refresh. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The access token and its nonce always arrive together, so proofNonce is set when a nonce is received, without comparing access tokens. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
stomita
marked this pull request as draft
November 22, 2026 18:15
beforeSend() used the access token from the connection, or with DPoP the one in a DPoP-only argument. HttpApi now reads the access token once for each request, makes the proof with it when DPoP is used, and passes both to beforeSend(), so HttpApi, SOAP and Bulk 1 put the same token in the request. The SOAP session expiry check no longer builds its regular expression from a string. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Also drop the comments on TokenResponse.extra, which the other fields of the type do not have. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The SalesforceProxy-Redirect headers are part of the protocol between XdProxyTransport and jsforce-ajax-proxy, but the request functions for Node and the browser handled them. XdProxyTransport now follows a redirect that the proxy reported in headers, and leaves other redirects to the request functions as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
beforeSend() puts the credentials in a request, so it now also makes the DPoP proof, reading the access token and the nonce from the connection like the Bearer token before. HttpApi no longer reads them itself or passes them around, and beforeSend() may return a promise. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The followRedirect function passed for DPoP now only puts a new proof on the redirected request that the default or the given followRedirect makes, instead of rebuilding its headers in a separate method. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Response header names are already lower-cased, the DPoP header is set under one name, and DPoP.createProof() already rejects a URL other than HTTPS, so getHeader(), withoutHeader() and isHttpsUrl() are not needed. Also build the request options before sending them to the transport. Co-Authored-By: Claude Opus 5.5 <[email protected]>
stomita
marked this pull request as ready for review
November 22, 2026 19:40
The browser tests run without the Node build, so test/oauth2.test.ts failed to load '../lib/request-helper' there. The mock transports build their responses themselves, and the test of performRedirectRequest is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The app has the certificate of SF_OAUTH2_JWT_KEY, so that the tests can get tokens for the scratch org by the JWT bearer flow. External client apps need a newer API version, so package.xml is raised to 68.0, and the permission set gets FreezeUsers and MonitorLoginHistory, which InstallPackaging depends on in that version. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A mock transport answers whatever is sent, so it cannot tell whether Salesforce accepts the requests. The DPoP tests now check only proofs made by the public API without sending requests, and check against the scratch org that a token from the JWT bearer flow is bound to the key, is refreshed once when invalid, is used by another connection with a saved nonce without refreshing, and is revoked by logout. The JWT bearer flow is also tested by itself. The assertion is signed with jwtKey.txt, which scripts/org-setup.mjs writes. In the browser, a karma middleware signs it, so that the key stays out of the browser. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tests after the first one use the token, so the connection is authorized in beforeAll instead of in the first test. The first test also checks that the DPoP connection can call the API with the token, in addition to that a connection without DPoP cannot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
In CI, lint runs before the build, so the type of Query is not known there and @typescript-eslint/require-await reports the async callbacks of assert.rejects() that only return the query. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…arer flow A consumer key of an external client app is unique across orgs, so a fixed key in the metadata works only in the first org it is deployed to. Read the key the org generates on deploy in scripts/org-setup.mjs, and pass it to the tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This branch has not been deployed
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.
Closes #1867
Starting 2027-03-30, Salesforce will block installing connected apps and external client apps into other orgs if they do not enable and lock PKCE, refresh token rotation, and at least one proof-of-possession (PoP) control (a refresh token IP allowlist or DPoP); see Security Change: PKCE, Refresh Token Rotation, and Proof-of-Possession. Existing connections keep working. So that apps choosing DPoP can keep using Salesforce APIs through jsforce, this PR adds support for DPoP as defined in RFC 9449.
Goals
Scope
DPoPorBearerscheme inAuthorization, orX-SFDC-Session, each with a proof) withInvalidSessionId, on API versions 31.0, 45.0, 62.0 and 68.0. REST and Bulk 2.0 worked with the same token at the same moment.Public API
dpopoption on theOAuth2config takes{ signer }. TheOAuth2instance holds aDPoPinstance made from it inoauth2.dpop, and a Connection using thatOAuth2sends its requests with DPoP.DPoPSigneris exported.DPoPclass is exported:DPoP.createSigner(key)creates a signer from aCryptoKeyPairor a PKCS#8 PEM P-256 private key. It works in both Node and the browser with no extra dependency.createProof({ method, url, accessToken, nonce })creates a proof with the signer.format, so KMS keys can be used too.requestToken(),refreshToken()andauthenticate()return the token response as before, withextra.proofNonceadded: the nonce received while obtaining the token.extrais added by jsforce and is not part of the response from Salesforce.Connection#proofNonceholds the nonce that API requests need (see "Nonce" below). It can be passed in the Connection config, next toaccessToken.Usage
Once the signer is passed, authorization and API calls are written the same way as today.
In Node, with a key stored as PEM:
In the browser, with a WebCrypto key. The private key can stay non-extractable:
With a KMS key, implement
DPoPSigneryourself and pass it in:To create a connection later from saved tokens without a refresh, save
proofNoncewith them:A refresh changes the access token and
proofNonce, and also the refresh token when Salesforce rotates it. The connection already has the new values when therefreshevent fires, so save them again then.Nonce
Salesforce requires a nonce in DPoP proofs. It gives the nonce only at the token endpoint (
use_dpop_nonce), not at API endpoints, and the nonce belongs to the session of the access token. It is valid for 24 hours.jsforce keeps the nonce received with a token in
proofNonceand uses it in API requests. A connection created from a saved access token withoutproofNonceneeds a refresh before its first API call succeeds.Behavior
revokeToken(), anddpop_jktis added togetAuthorizationUrl(). Salesforce does not revoke a DPoP token when the revoke request has no proof.DpopProofHeaderSOAP header next toSessionHeader. With DPoP, Salesforce reports an expired or revoked token as anINVALID_AUTH_HEADERfault, so that fault also triggers the refresh.proxyUrl; use HTTPS outside local development.Left to users
jsforce does not store keys or tokens. The following are left to users:
DPoPSignerwhen using a KMS or HSM key.proofNoncewith the access token, to use the access token in another process without a refresh.Implementation notes
src/oauth2.ts, in theDPoPclass.OAuth2uses it for token and revoke requests.HttpApiandSOAPmake the proof inbeforeSend(), which may now return a promise, with the access token they put in the request;SOAPputs the proof in the envelope.followRedirectfunction option may now return a promise, andHttpApiandOAuth2pass a function that builds the redirected request with a new proof.XdProxyTransportused to drop the request options. It now passes them through, so options such astimeoutandfollowRedirect: falsealso take effect through the proxy, with or without a signer. In the browser, a failedfetch(such as a timeout or a CORS error) now ends the request with the error, instead of leaving it pending.followRedirectfunction,XdProxyTransportasks jsforce-ajax-proxy to report redirects in headers instead. This applies to afollowRedirectfunction passed without a signer too, so such requests through a cross-origin proxy need a proxy that supports it. Using DPoP in the browser through the proxy needs jsforce-ajax-proxy 2.1.0 or later.Tests
The DPoP tests in
test/oauth2.test.tscheck what jsforce sends, in both Node and the browser:DPoP.createSigner(), or with a custom signer returning DER, verify against the signer's public key.jtifor each request.dpop_jktin the authorization URL is the RFC 7638 thumbprint of the key.DpopProofHeader, with the same access token inSessionHeader.Whether Salesforce accepts them was checked against a scratch org with DPoP enabled on an external client app: authorization, REST, Bulk 2.0, SOAP, Metadata, refresh and revoke, from Node (directly and through jsforce-ajax-proxy) and from the browser (with a non-extractable WebCrypto key, through jsforce-ajax-proxy).