|
1 |
| -@page "~/jwt-decoder" |
| 1 | +@page "~/jwt-decoder" |
2 | 2 | @model IdentityServerHost.Pages.Home.JwtDecoder
|
3 | 3 |
|
4 | 4 | <!-- Google Tag Manager (noscript) -->
|
|
56 | 56 | </div>
|
57 | 57 | </div>
|
58 | 58 | </div>
|
59 |
| - <div class="col-12 col-md-6 pb-4 pb-md-0"> |
| 59 | + <div class="col-jwt col-12 col-md-6 pb-4 pb-md-0"> |
60 | 60 | <h3>Decoded JWT</h3>
|
61 | 61 | <div class="jwt-decoded-output">
|
62 | 62 | <h4>Header</h4>
|
|
108 | 108 | signature: null
|
109 | 109 | };
|
110 | 110 |
|
111 |
| - let explainClaims = false; |
| 111 | + const optionsKey = 'jwtDecoderSettings'; |
| 112 | + let options = { |
| 113 | + presenterMode: false, |
| 114 | + explainClaims: false |
| 115 | + }; |
112 | 116 |
|
113 | 117 | function defaultJsonStringifyReplacer(key, value) {
|
114 | 118 | if (value === null || value === undefined) {
|
|
277 | 281 |
|
278 | 282 | $(document).ready(initializeJwtDecoder);
|
279 | 283 |
|
| 284 | + function readSettingsFromStorage() { |
| 285 | + try { |
| 286 | + const settings = window.localStorage.getItem(optionsKey); |
| 287 | + if (settings) { |
| 288 | + options = JSON.parse(settings); |
| 289 | + } |
| 290 | +
|
| 291 | + $('#explainClaims').prop('checked', options.explainClaims); |
| 292 | + $('#togglePresenterMode').prop('checked', options.presenterMode); |
| 293 | + jsonStringifyReplacer = options.explainClaims ? expandedJsonStringifyReplacer : defaultJsonStringifyReplacer; |
| 294 | + setPresenterMode(options.presenterMode); |
| 295 | + } |
| 296 | + catch (e) {} |
| 297 | + } |
| 298 | + |
| 299 | + function saveSettingsToStorage() { |
| 300 | + window.localStorage.setItem(optionsKey, JSON.stringify({ |
| 301 | + explainClaims: options.explainClaims, |
| 302 | + presenterMode: options.presenterMode |
| 303 | + })); |
| 304 | + } |
| 305 | + |
| 306 | + function setPresenterMode(enabled) { |
| 307 | + if (enabled) { |
| 308 | + $('.row-jwt').removeClass('align-items-stretch'); |
| 309 | + $('.col-jwt').removeClass('col-md-6'); |
| 310 | + $('#jwt-input').parent().removeClass('flex-grow-1'); |
| 311 | + } |
| 312 | + else { |
| 313 | + $('.row-jwt').addClass('align-items-stretch'); |
| 314 | + $('.col-jwt').addClass('col-md-6'); |
| 315 | + $('#jwt-input').parent().addClass('flex-grow-1'); |
| 316 | + } |
| 317 | + } |
| 318 | + |
280 | 319 | async function initializeJwtDecoder() {
|
281 |
| - const explainClaimsCheckbox = $('#explainClaims'); |
282 |
| - explainClaims = explainClaimsCheckbox.is(':checked'); |
283 |
| - explainClaimsCheckbox.on('change', function() { |
284 |
| - explainClaims = this.checked; |
285 |
| - jsonStringifyReplacer = explainClaims ? expandedJsonStringifyReplacer : defaultJsonStringifyReplacer; |
| 320 | + await readSettingsFromStorage(); |
| 321 | + |
| 322 | + $('#explainClaims').on('change', async function() { |
| 323 | + options.explainClaims = this.checked; |
| 324 | + await saveSettingsToStorage(); |
| 325 | + jsonStringifyReplacer = options.explainClaims ? expandedJsonStringifyReplacer : defaultJsonStringifyReplacer; |
286 | 326 | updateClaimsExplanation();
|
287 | 327 | });
|
| 328 | +
|
| 329 | + $('#togglePresenterMode').on('change', async function() { |
| 330 | + options.presenterMode = this.checked; |
| 331 | + await saveSettingsToStorage(); |
| 332 | + |
| 333 | + setPresenterMode(options.presenterMode); |
| 334 | + }); |
288 | 335 |
|
289 | 336 | $('#jwt-input').on('input', async function() {
|
290 | 337 | decodedJwt = {
|
|
0 commit comments