blob: d70a67e3160934a68b701900c4e8a115dc21bf7e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
<template>
<n-card>
<n-form-item label="JWT to decode" :feedback="validation.message" :validation-status="validation.status">
<n-input v-model:value="raw_jwt" type="textarea" placeholder="Put your token here..." rows="5" />
</n-form-item>
<n-form-item label="Display parsed value?" label-placement="left" :show-feedback="false">
<n-switch v-model:value="showParsedValues" />
</n-form-item>
<n-table>
<tbody>
<td colspan="2" class="table-header"><strong>Header</strong></td>
<tr v-for="[key, value] in Object.entries(decodedJWT.header)" :key="key">
<td class="claims"><claim-vue :claim="key" /></td>
<td>
<span v-if="!showParsedValues">{{ value }}</span>
<value-vue v-else :claim="key" :value="value" />
</td>
</tr>
<td colspan="2" class="table-header"><strong>Payload</strong></td>
<tr v-for="[key, value] in Object.entries(decodedJWT.payload)" :key="key">
<td class="claims"><claim-vue :claim="key" /></td>
<td>
<span v-if="!showParsedValues">{{ value }}</span>
<value-vue v-else :claim="key" :value="value" />
</td>
</tr>
</tbody>
</n-table>
</n-card>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue';
import jwt_decode from 'jwt-decode';
import { useValidation } from '@/composable/validation';
import { isNotThrowing } from '@/utils/boolean';
import { safe_jwt_decode } from './jwt-parser.service';
import claimVue from './claim.vue';
import valueVue from './value.vue';
const raw_jwt = ref(
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
);
const showParsedValues = ref(true);
const decodedJWT = computed(() => {
return safe_jwt_decode(raw_jwt.value);
});
const validation = useValidation({
source: raw_jwt,
rules: [
{
validator: (value) => value.length > 0 && isNotThrowing(() => jwt_decode(value, { header: true })),
message: 'Invalid JWT',
},
],
});
</script>
<style lang="less" scoped>
.table-header {
text-align: center;
}
.claims {
width: 20%;
}
</style>
|