Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Add token validation to didAuthError and allowable clock skew to willAuthError #12418

Merged
merged 2 commits into from
Jan 6, 2025

Conversation

petertgiles
Copy link
Contributor

🤖 Resolves #12369

👋 Introduction

We've been getting lots of reports of premature logouts with our app. Our best explanation is that the Surface tablets appear to have over 5 seconds of clock skew which means that the client is attempting to use an expired token. Also, URQL is not configured to recognize the token_validation error and so it does not attempt to refresh when it gets the error. This PR attempts to fix both problems.

🕵️ Details

🧪 Testing

DidAuthError

  1. Rebuild and log in to app
  2. Add "throw new Exception('Failed to get introspection');" to the top of verifyJwtWithIntrospection in api/app/Services/OpenIdBearerTokenService.php and to simulate an expired token.
  3. Make an API call in your browser
  • URQL will try to refresh ONCE and then force a log out.

WillAuthError

  1. Manually change allowableClockSkewSeconds in packages/client/src/constants.ts to something very large, like 8 * 60.
  2. Rebuild and log into app.
  3. Wait until you enter the skew zone, like 2 minutes and make an api call.
  • URQL will try to refresh ONCE and and be successful

📸 Screenshot

image

(e) => e.extensions?.category === "authentication",
(e) =>
e.extensions?.category === "authentication" ||
e.extensions?.reason === "token_validation", // the auth provider says the token is invalid - maybe just a refresh is needed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The cleaner solution might be to update our openID provider to return a 401. This would be a bigger change because a lot of tests watch for this reason code now.

@petertgiles petertgiles marked this pull request as ready for review January 3, 2025 20:38
tokenIsKnownToBeExpired = Date.now() > decoded.exp * 1000; // JWT expiry date in seconds, not milliseconds
const tokenExpiryDateSeconds = decoded.exp;
const safeTokenExpiryDateSeconds =
tokenExpiryDateSeconds - allowableClockSkewSeconds; // allow for the client's machine to be a bit off
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah .. this is what I did as well .. but I didn't see the refresh happening earlier than 10 mins .. may be let's try yours

Copy link
Contributor

@brindasasi brindasasi left a comment

Choose a reason for hiding this comment

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

This is looking like great to me and I didn't see any log out in UAT. I'm up for trying this out in prod tonight

@petertgiles petertgiles added this pull request to the merge queue Jan 6, 2025
Merged via the queue into main with commit e996159 Jan 6, 2025
17 checks passed
@petertgiles petertgiles deleted the 12369-logout-issues branch January 6, 2025 19:15
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.

🐛 Do multiple tab interactions lead to early log out?
2 participants