Skip to content

Commit e910869

Browse files
authored
regen nonce, code_challenge (#91)
1 parent 66dcc38 commit e910869

3 files changed

Lines changed: 51 additions & 10 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<svg
2+
xmlns="http://www.w3.org/2000/svg"
3+
fill="none"
4+
viewBox="0 0 24 24"
5+
stroke-width="2.5"
6+
stroke="currentColor"
7+
class="size-6 h-4 w-4"
8+
>
9+
<path
10+
stroke-linecap="round"
11+
stroke-linejoin="round"
12+
d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99"
13+
/>
14+
</svg>

src/lib/components/Request/ProtocolParams.svelte

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<script>
22
import { slide } from 'svelte/transition';
33
import { PARAMS } from '$lib/constants.js';
4+
import { validateProtocolParams as validate } from '$lib/validate.js';
5+
import { generatePkce } from '$lib/utils';
46
import ChevronY from '$components/ChevronY.svelte';
57
import Tooltip from '$components/Tooltip.svelte';
6-
import { validateProtocolParams as validate } from '$lib/validate.js';
8+
import RedoIcon from '../Icons/RedoIcon.svelte';
79
810
let {
911
selectedProtocolParams = $bindable(),
@@ -12,6 +14,19 @@
1214
selectedHelloParamsValues,
1315
dropdowns = $bindable()
1416
} = $props();
17+
18+
async function regen(param) {
19+
if (param === 'nonce') {
20+
const { nonce } = await generatePkce();
21+
selectedProtocolParamsValues.nonce = nonce;
22+
} else if (param === 'code_challenge') {
23+
const { code_challenge, code_verifier } = await generatePkce();
24+
selectedProtocolParamsValues.code_challenge = code_challenge;
25+
selectedProtocolParamsValues.code_verifier = code_verifier;
26+
} else {
27+
console.error('Unknown parameter for regeneration', param);
28+
}
29+
}
1530
</script>
1631

1732
<section class="break-inside-avoid-column">
@@ -94,13 +109,23 @@
94109
{/each}
95110
</ul>
96111
{:else}
97-
<input
98-
type="text"
99-
class="form-input h-6 w-full border px-2"
100-
class:opacity-50={!selected}
101-
bind:value={selectedProtocolParamsValues[param.NAME]}
102-
placeholder={param.PLACEHOLDER}
103-
/>
112+
<div class="relative flex w-full items-center" class:opacity-50={!selected}>
113+
{#if param.REGENERATE}
114+
<button
115+
onclick={() => regen(param.NAME)}
116+
class="absolute right-0.5 z-10 inline-flex h-5 w-5 items-center justify-center border border-charcoal bg-charcoal dark:border-gray-800"
117+
>
118+
<RedoIcon />
119+
</button>
120+
{/if}
121+
<input
122+
type="text"
123+
class="form-input h-6 w-full border px-2"
124+
class:pr-6={param.REGENERATE}
125+
bind:value={selectedProtocolParamsValues[param.NAME]}
126+
placeholder={param.PLACEHOLDER}
127+
/>
128+
</div>
104129
{/if}
105130
</li>
106131
{/each}

src/lib/constants.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const PROTOCOL_PARAM = {
3232
},
3333
{
3434
NAME: 'nonce',
35-
POSSIBLE_VALUE: ''
35+
POSSIBLE_VALUE: '',
36+
REGENERATE: true
3637
},
3738
{
3839
NAME: 'response_type',
@@ -41,7 +42,8 @@ const PROTOCOL_PARAM = {
4142
},
4243
{
4344
NAME: 'code_challenge',
44-
POSSIBLE_VALUE: ''
45+
POSSIBLE_VALUE: '',
46+
REGENERATE: true
4547
},
4648
{
4749
NAME: 'code_verifier',

0 commit comments

Comments
 (0)