mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 22:02:38 +03:00
feat(JWT Generator): allow to paste an existing token to edit
Fix #1668
This commit is contained in:
1 parent
b24021771b
commit
23581a34b0
2 files changed
+33
No files matched your search
@@ -2513,6 +2513,8 @@ tools:
|
|||||||
token-keys: Token Keys
|
token-keys: Token Keys
|
||||||
cannot-parse-secret-as-encoding: 'Cannot parse ''{0}'' as ''{1}'': {2}'
|
cannot-parse-secret-as-encoding: 'Cannot parse ''{0}'' as ''{1}'': {2}'
|
||||||
invalid-base64-string: Invalid Base64 string
|
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:
|
length-converter:
|
||||||
title: Length Units Converter
|
title: Length Units Converter
|
||||||
description: Convert values from length units
|
description: Convert values from length units
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import { type KeyLike } from 'jose';
|
|||||||
import JSON5 from 'json5';
|
import JSON5 from 'json5';
|
||||||
import hexArray from 'hex-array';
|
import hexArray from 'hex-array';
|
||||||
import { Base64 } from 'js-base64';
|
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 { jwsAlgorithms } from './jwt-generator.constants';
|
||||||
|
|
||||||
import { useValidation } from '@/composable/validation';
|
import { useValidation } from '@/composable/validation';
|
||||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
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 algInfo = computed(() => jwsAlgorithms.find(a => a.alg === alg.value) || { alg: 'UNK', keyDesc: '', key: 'secret', verify: '' });
|
||||||
const isSecret = computed(() => algInfo.value.key === 'secret');
|
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 secret = ref('');
|
||||||
const secretEncoding = ref<'text' | 'base64' | 'hex'>('text');
|
const secretEncoding = ref<'text' | 'base64' | 'hex'>('text');
|
||||||
const encodings = [
|
const encodings = [
|
||||||
@@ -139,6 +155,21 @@ const jsonInputValidation = useValidation({
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<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
|
<c-select
|
||||||
v-model:value="alg"
|
v-model:value="alg"
|
||||||
:options="jwsAlgorithms.map(a => ({ value: a.alg, label: `${a.alg}: ${a.verify}` }))"
|
:options="jwsAlgorithms.map(a => ({ value: a.alg, label: `${a.alg}: ${a.verify}` }))"
|
||||||
|
|||||||
Reference in new issue
Block a user