Improve auth failure diagnostics #295
Merged
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.
The specific scenario here is that if a JWKS takes longer than 3 seconds to complete, there would be very little info in the logs on what is happening. The logs would include a message such as
Known kid values: powersync-api, *, powersync-dev
, without any further details.Note that we have two timeouts applying to JWKS URIs:
CachedKeyCollector
returns a response after 3s, while letting the refresh continue in the background.RemoteJWKSCollector
has a hard timeout of 30s.This improves the error and timeout timeout handling in a couple of ways:
Known keys: <kid: powersync-api, kty: oct, alg: HS256>, <kid: *, kty: oct, alg: HS256, aud: authenticated>, <kid: powersync-dev, kty: RSA, alg: RS256>
.For the timeout, the issue was that the CachedKeyCollector would return the current keys after a 3-second timeout, with no error message. But if that was the first request, there would be no keys and no errors, giving no indication on what is happening. This changes it to return an error message. Note that if there are already relevant keys cached, those would still be used.
With these changes, you'd now see this in the logs in the case of a timeout: