fix: attempt DPoP up front in private-key token flow - #597
Open
turkdogan wants to merge 1 commit into
Open
Conversation
The private-key client-credentials flow obtained tokens reactively: it sent the first /oauth2/v1/token request without a DPoP proof, let Okta reject it with invalid_dpop_proof, then retried with a proof. For an app with "Require DPoP" enabled, each token acquisition that takes this path makes an extra round trip (3 requests instead of 2) and records a failed token grant in the org System Log. Attempt DPoP up front instead (per RFC 9449): pre-generate one key, attach a proof to the first token request, and reuse the key across the use_dpop_nonce retry. Adapt to the first response — keep DPoP if Okta issues a DPoP-bound token, fall back to Bearer if the app does not require DPoP (Okta ignores the unsolicited proof). getAccessTokenForDpopPrivateKey is folded into the main flow and removed. No public API change; non-DPoP apps are unaffected.
Author
|
I've signed and emailed the Okta Individual CLA (GitHub: turkdogan, email: turkdogan.tasdelen@backupta.com). |
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.
Summary
The private-key / JWT client-credentials flow obtained tokens reactively: it sent the first
/oauth2/v1/tokenrequest without a DPoP proof, let Okta reject it withinvalid_dpop_proof, then retried with a proof. For an app with Require DPoP enabled, every token acquisition on this path costs an extra round trip (3 requests instead of 2) and records a failed token grant in the org System Log.This PR attempts DPoP up front, per RFC 9449: pre-generate one DPoP key, attach a proof to the first token request, and reuse that key across the
use_dpop_nonceretry. The flow then adapts to the first response:getAccessTokenForDpopPrivateKeyis folded into the main flow and removed. No public API change; non-DPoP apps are unaffected (still a single token request).The change is authored in
.generator/templates/client.mustache(the source template) andokta/client.gois regenerated from it — both are committed so a future regeneration stays consistent. While in the flow I also aligned the DPoP/Bearer check to the codebase's exactTokenType != "DPoP"convention (the callers already use exact matching) and corrected a comment about backoff retry behavior.Known limitation: in
JWTAuthmode (caller-suppliedclient_assertion, no signer) against a Require-DPoP org, theuse_dpop_nonceretry replays the same assertion, which Okta may reject as a reusedjti. Callers needing DPoP should usePrivateKeyAuth/JWKAuthso the SDK can mint a fresh single-use assertion. Non-DPoP orgs and the key-based modes are unaffected.Fixes #598
Type of PR
Test Information
Go Version: 1.24 (module minimum; locally tested with go1.26)
Os Version: macOS (darwin/arm64)
OpenAPI Spec Version: N/A — no spec change; the fix is authored in the
client.mustachetemplate andokta/client.gois regenerated from itSignoff
make fmton my code.generator/templates/client.mustache;okta/client.gois the regenerated output committed alongside)