|
48 | 48 | </div>
|
49 | 49 | <div class="form-group">
|
50 | 50 | <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" /> |
52 | 52 | <small id="jwks-url-help" class="form-text text-muted">
|
53 | 53 | Optionally, you can provide the issuer, discovery document or JWKs URI to validate the JWT's signature.
|
54 | 54 | If you leave this field empty, the tool will use the value of the 'iss' claim.
|
|
333 | 333 | setPresenterMode(options.presenterMode);
|
334 | 334 | });
|
335 | 335 |
|
| 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 | + |
336 | 348 | $('#jwt-input').on('input', async function() {
|
337 | 349 | decodedJwt = {
|
338 | 350 | header: null,
|
|
407 | 419 | }
|
408 | 420 |
|
409 | 421 | 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. |
413 | 428 | jwksUrl = payload.iss;
|
414 |
| - $('#jwks-url').val(jwksUrl); |
| 429 | + jwksUrlField.val(jwksUrl); |
415 | 430 | }
|
416 | 431 |
|
417 | 432 | if (jwksUrl) {
|
|
0 commit comments