Skip to content

feat: syncs time with Authorization Server date header#16

Open
jaredperreault-okta wants to merge 5 commits into0.5from
jp-time-coordinator
Open

feat: syncs time with Authorization Server date header#16
jaredperreault-okta wants to merge 5 commits into0.5from
jp-time-coordinator

Conversation

@jaredperreault-okta
Copy link
Contributor

No description provided.

@jaredperreault-okta jaredperreault-okta changed the base branch from master to 0.5 March 2, 2026 12:33
nonce
};

console.log('claims', claims);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll remove

if (!(
OAuth2Client.isDPoPProofClockSkewError(json) && // proper error is returned from AS
request.canRetry() && // request hasn't been retried too many times previously
Math.abs(Date.now() - TimeCoordinator.clockSkew) >= 150 // the TimeCoordinator updated with a meaningful time difference (~2.5 mintues)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to put this clock skew value into a const stored elsewhere.

Comment on lines +205 to +207
if (!(
OAuth2Client.isDPoPProofClockSkewError(json) && // proper error is returned from AS
request.canRetry() && // request hasn't been retried too many times previously

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you're trying to do an early return to return the JSON response to the caller, but the !(expression && expression) logic makes my brain go fuzzy reading it. It's not clear to me what conditions need to be met to consider the need to retry the response.

It might be clearer to break the expression up a bit, or to perform the JWT sign and retry process at the same time as checking for a time-skew error.

// this will align the client's clock with the Authorization Server's
await this.signTokenRequestWithDPoP(request); // re-sign request (with new `TimeCoordinator.now()`)
const retryReponse = await this.retry(request); // trigger retry
json = await retryReponse.json();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not returning the json returned from the retry here.

Copy link
Contributor Author

@jaredperreault-okta jaredperreault-okta Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this block is a little confusing but the gist is:

if (isOAuth2ErrorResponse(json) {
  // if dpop proof clock skew error
  retry()   // this is return a response other than `OAuth2ErrorResponse`

  //else
  return json;
}

Comment on lines +589 to +593
export function isDPoPProofClockSkewError (error: OAuth2ErrorResponse) {
return error.error === 'invalid_dpop_proof' && (
error.error_description === 'The DPoP proof JWT is issued in the future.' ||
error.error_description === 'The DPoP proof JWT is issued more than five minutes in the past.'
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these Okta-specific errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so, I didn't them mentioned in the spec

authentication?: ClientAuthentication;
allowHTTP?: boolean;
}
syncClockWithAuthorizationServer?: boolean;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you anticipate any occasions where a developer wouldn't want to adjust clock skew? In the other SDKs that implement clock skew, the default implementation just does it automatically since it's almost always what the developer would want. If clock skew is not wanted, then it's simpler to assign a different TimeCoordinator instance which doesn't perform clock correction, this way the clock behavior is consistent across the whole SDK.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and implementing this here, at the OAuth2 configuration level, doesn't help with clcok skew corrections in other parts of the SDK where they may be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants