added base tool structure

This commit is contained in:
bastantoine 2022-11-18 18:36:18 +01:00
parent 3e4a64551f
commit bb0eca80a7
4 changed files with 42 additions and 0 deletions

View file

@ -1,6 +1,7 @@
import { LockOpen } from '@vicons/tabler';
import type { ToolCategory } from './tool';
import { tool as jwtParser } from './jwt-parser';
import { tool as mimeTypes } from './mime-types';
import { tool as otpCodeGeneratorAndValidator } from './otp-code-generator-and-validator';
import { tool as base64FileConverter } from './base64-file-converter';
@ -67,6 +68,7 @@ export const toolsByCategory: ToolCategory[] = [
metaTagGenerator,
otpCodeGeneratorAndValidator,
mimeTypes,
jwtParser,
],
},
{

View file

@ -0,0 +1,11 @@
import { ArrowsShuffle } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'JWT parser',
path: '/jwt-parser',
description: '',
keywords: ['jwt', 'parser'],
component: () => import('./jwt-parser.vue'),
icon: ArrowsShuffle,
});

View file

@ -0,0 +1,20 @@
import jwt_decode, { InvalidTokenError } from 'jwt-decode';
interface JWT {
header: Map<string, unknown>;
payload: Map<string, unknown>;
}
export function safe_jwt_decode(raw_jwt: string): JWT {
try {
const header = jwt_decode(raw_jwt, { header: true }) as Map<string, unknown>;
const payload = jwt_decode(raw_jwt) as Map<string, unknown>;
return { header: header, payload: payload };
} catch (e) {
if (e instanceof InvalidTokenError) {
return { header: new Map<string, unknown>(), payload: new Map<string, unknown>() };
} else {
throw e;
}
}
}

View file

@ -0,0 +1,9 @@
<template>
</template>
<script setup lang="ts">
</script>
<style lang="less" scoped></style>