feat(adapters): salesforce JWT bearer grant (RFC 7523) - #61
Merged
Conversation
The token endpoint accepts grant_type=urn:ietf:params:oauth:grant-type: jwt-bearer with an RS256 assertion, verified like the real endpoint: 3 base64url segments, alg RS256, RSA-SHA256 signature against the adapter's fixed connected-app certificate, iss non-empty, sub (or legacy prn) non-empty, aud a Salesforce login host, exp in the future. A valid assertion mints a normal session for the sub user with no refresh_token (fresh assertions replace refresh); failures return the real invalid_grant 400. Closes the last item of the salesforce sweep issue (SOQL v0.22.0, SObject Collections v0.37.0).
Review findings on PR #61, all fixed: - iss/sub/prn claims must be actual strings: JSON null decodes to Starlark None and None == "" is False, so a signed {"sub":null} assertion minted a session with a null username past the emptiness guards. _claim_str (mirrors _claim_int) now gates iss, sub, prn and the username extraction. Same latent hole fixed in google-iam's iss check, with a pinned null-iss negative. - exp must be within ~5 minutes of now (plus the documented clock-skew allowance) — the real endpoint rejects long-lived assertions, so a client minting them should fail against stunt too. - tests now pin: prn legacy fallback, sandbox aud, alg!=RS256, null sub/iss, float exp, exp==now boundary, 1h exp rejection.
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.
What
salesforce-stylegains the JWT bearer OAuth flow — the server-to-server grant real connected apps use — closing the last item of the salesforce sweep issue (SOQL shipped in v0.22.0, SObject Collections in v0.37.0).POST /services/oauth2/tokennow acceptsgrant_type=urn:ietf:params:oauth:grant-type:jwt-bearerwith anassertion, verified the way the real endpoint does (modulo the fixed mock certificate):alg == RS256header.payloadagainst the adapter's fixed "connected-app certificate" (the repo's throwaway keypair material; public half inscripts/oauth.star, private half only in tests — mirroring how a real app's cert is registered out of band)issnon-empty (consumer key),sub(or legacyprn) non-empty,aud∈ {https://login.salesforce.com,https://test.salesforce.com},expin the futureA valid assertion mints a normal session token for the
subuser. The response carries norefresh_token— a JWT-bearer client mints a fresh assertion instead of refreshing (matches the real flow). Failures return400 {"error":"invalid_grant","error_description":"invalid assertion"}; a missing assertion isinvalid_request.Test
TestSalesforceStyleJWTBearerGrant: real RS256 assertions signed in Go —00Daccess token,Bearer, no refresh_token, and the token authorizes a SOQL query (proves it's a real session)Gates: parse guard, QC boot, adapter lint, full
go test ./..., gofmt, go vet — all green.