feat(JWT Generator): allow to paste an existing token to edit

Fix #1668
This commit is contained in:
ShareVB committed 2025-11-23 21:12:30 +01:00
1 parent b24021771b
commit 23581a34b0
2 files changed
+33

No files matched your search

+2
View File
@@ -2513,6 +2513,8 @@ tools:
token-keys: Token Keys
cannot-parse-secret-as-encoding: 'Cannot parse ''{0}'' as ''{1}'': {2}'
invalid-base64-string: Invalid Base64 string
placeholder-input-token: Paste your JWT token to edit...
click-to-input-a-existing-jwt-token-to-modify: Click to input a existing JWT token to modify
length-converter:
title: Length Units Converter
description: Convert values from length units
+31
View File
@@ -5,7 +5,10 @@ import { type KeyLike } from 'jose';
import JSON5 from 'json5';
import hexArray from 'hex-array';
import { Base64 } from 'js-base64';
import { type JwtPayload, jwtDecode } from 'jwt-decode';
import { getJwtAlgorithm } from '../jwt-parser/jwt-parser.service';
import { jwsAlgorithms } from './jwt-generator.constants';
import { useValidation } from '@/composable/validation';
import { useQueryParamOrStorage } from '@/composable/queryParams';
@@ -21,6 +24,19 @@ const alg = useQueryParamOrStorage({ name: 'alg', storageName: 'jwt-gen:alg', de
const algInfo = computed(() => jwsAlgorithms.find(a => a.alg === alg.value) || { alg: 'UNK', keyDesc: '', key: 'secret', verify: '' });
const isSecret = computed(() => algInfo.value.key === 'secret');
const inputToken = ref('');
const inputTokenError = ref('');
watch(inputToken, (value) => {
inputTokenError.value = '';
try {
payload.value = JSON.stringify(jwtDecode<JwtPayload>(value), null, 2);
alg.value = getJwtAlgorithm({ jwt: value }) || 'HS512';
}
catch (e: any) {
inputTokenError.value = e.toString();
}
});
const secret = ref('');
const secretEncoding = ref<'text' | 'base64' | 'hex'>('text');
const encodings = [
@@ -139,6 +155,21 @@ const jsonInputValidation = useValidation({
<template>
<div>
<c-card mb-3>
<details>
<summary>
{{ t('tools.jwt-generator.texts.click-to-input-a-existing-jwt-token-to-modify') }}
</summary>
<c-input-text
v-model:value="inputToken"
:placeholder="t('tools.jwt-generator.texts.placeholder-input-token')"
/>
<c-alert v-if="inputTokenError">
{{ inputTokenError }}
</c-alert>
</details>
</c-card>
<c-select
v-model:value="alg"
:options="jwsAlgorithms.map(a => ({ value: a.alg, label: `${a.alg}: ${a.verify}` }))"