Skip to content

Commit 8f7d317

Browse files
committed
Detect pristine mode to keep autoloading the JWKS url
1 parent 2311c3c commit 8f7d317

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/Pages/Home/JwtDecoder/JwtDecoder.cshtml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</div>
4949
<div class="form-group">
5050
<label for="jwks-url">Issuer, Discovery Document or JWKs URI</label>
51-
<input type="url" class="form-control mb-2 mr-sm-2" id="jwks-url" name="jwks-url" aria-describedby="jwks-url-help" />
51+
<input type="url" class="form-control mb-2 mr-sm-2" id="jwks-url" name="jwks-url" aria-describedby="jwks-url-help" data-pristine="true" />
5252
<small id="jwks-url-help" class="form-text text-muted">
5353
Optionally, you can provide the issuer, discovery document or JWKs URI to validate the JWT's signature.
5454
If you leave this field empty, the tool will use the value of the 'iss' claim.
@@ -333,6 +333,18 @@
333333
setPresenterMode(options.presenterMode);
334334
});
335335
336+
// Little helper to track if the JWKS URL field is pristine (not modified).
337+
// While it is pristine or empty, we will use the 'iss' claim from the JWT payload to load JWKs.
338+
const jwksUrlField = $('#jwks-url');
339+
jwksUrlField.on('input', function() {
340+
const val = $(this).val();
341+
if (val === '' || val === null || val === undefined) {
342+
jwksUrlField.data('pristine', true);
343+
} else {
344+
jwksUrlField.data('pristine', false);
345+
}
346+
});
347+
336348
$('#jwt-input').on('input', async function() {
337349
decodedJwt = {
338350
header: null,
@@ -407,11 +419,14 @@
407419
}
408420
409421
async function attemptSignatureValidation(header, payload, jwtParts) {
410-
let jwksUrl = $('#jwks-url').val().trim();
411-
if (!jwksUrl && payload && payload.iss) {
412-
// If no JWKs URL is provided, use the issuer from the payload.
422+
const jwksUrlField = $('#jwks-url');
423+
424+
const isPristine = jwksUrlField.data('pristine') !== false;
425+
let jwksUrl = jwksUrlField.val().trim();
426+
if ((!jwksUrl || isPristine) && payload && payload.iss) {
427+
// If no JWKs URL is provided (or previously set from a different token's issuer), use the issuer from the payload.
413428
jwksUrl = payload.iss;
414-
$('#jwks-url').val(jwksUrl);
429+
jwksUrlField.val(jwksUrl);
415430
}
416431
417432
if (jwksUrl) {

0 commit comments

Comments
 (0)