ASA: switch OAuth token exchange to query-param + client_secret shape#6
Merged
Conversation
Apple's current Search Ads OAuth docs use URL query parameters with an empty body and pass the JWT as 'client_secret' rather than as a 'client_assertion' JWT-bearer assertion. Update ASATokenCache.exchange to match the documented shape so credentials minted from Apple's console work without massaging. - Move grant_type / client_id / client_secret / scope onto the URL query - Drop client_assertion_type, send an empty body - Stop sending X-AP-Context on the OAuth call (data calls still get it) - Refresh leading comment block to describe the new flow - Add a test asserting the OAuth URL contains all four query params and that X-AP-Context is absent on the exchange request
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
Update
ASATokenCache.exchangeinSources/App/Clients/AppleSearchAdsClient.swiftso the OAuth token-exchange request matches Apple's currently-documented Search Ads shape.client_assertion+client_assertion_type=urn:…:jwt-bearerclient_secretX-AP-Contexton OAuth callorgIdpresentReference (Apple's docs, dummy values):
Why
Apple shifted the public Search Ads OAuth surface: the JWT minted from the user's EC private key is now passed as
client_secretrather than as an RFC 7521 JWT-bearerclient_assertion. Credentials freshly generated from Apple's console were failing against the old wire shape withinvalid_client. This makes our exchange byte-for-byte identical to the docs' reference curl.No schema or settings-UI change —
ASACredentials.clientSecretalready holds the JWT; only the wire field name changes. Downstream campaign/report calls keepX-AP-ContextviaauthHeaders(token:)—X-AP-Contextis only removed from the OAuth hop, where Apple's docs don't include it.Reviewer notes
tokenCache_oauthRequestShapeasserts the OAuth URL contains all four query params and thatX-AP-Contextis absent on the exchange call. It also confirms thatpercent(_:)leaves RFC 3986 unreserved chars (-._~) literal, so the JWT's dots aren't double-encoded.Exchanged/OAuthResponsemodel and the 401-retry / cache-invalidate paths are unchanged.X-AP-Contexton the auth hop, flag it — easy to add back, but it's not in any current Apple doc I could find.Verification
swift build— cleanswift test --filter AppleSearchAdsClientTests— 7/7 pass (6 existing + 1 new)