@adminforth/two-factors-auth 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom/TwoFactorsConfirmation.vue +152 -0
- package/custom/TwoFactorsOtp.vue +0 -0
- package/custom/TwoFactorsSetup.vue +188 -0
- package/dist/custom/TwoFactorsConfirmation.vue +152 -0
- package/dist/custom/TwoFactorsOtp.vue +0 -0
- package/dist/custom/TwoFactorsSetup.vue +188 -0
- package/dist/index.js +136 -0
- package/dist/types.js +1 -0
- package/index.ts +140 -0
- package/package.json +16 -0
- package/tsconfig.json +112 -0
- package/types.ts +10 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="relative flex items-center justify-center min-h-screen bg-gray-100 dark:bg-gray-800"
|
|
3
|
+
:style="coreStore.config?.loginBackgroundImage ? {
|
|
4
|
+
'background-image': 'url(' + loadFile(coreStore.config?.loginBackgroundImage) + ')',
|
|
5
|
+
'background-size': 'cover',
|
|
6
|
+
'background-position': 'center',
|
|
7
|
+
'background-blend-mode': 'darken'
|
|
8
|
+
}: {}"
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
<div id="authentication-modal" tabindex="-1" class=" overflow-y-auto overflow-x-hidden z-50 min-w-[00px] justify-center items-center md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
|
12
|
+
<div class="relative p-4 w-full max-w-md max-h-full">
|
|
13
|
+
<!-- Modal content -->
|
|
14
|
+
<div class="relative bg-white rounded-lg shadow dark:bg-gray-700 dark:shadow-black text-gray-500" >
|
|
15
|
+
<div class="p-8 w-full max-w-md max-h-full" >
|
|
16
|
+
<div class="m-3" >Please enter your authenticator code </div>
|
|
17
|
+
|
|
18
|
+
<form class="max-w-sm mx-auto mt-6 flex flex-col items-center ">
|
|
19
|
+
<div class="flex mb-2 space-x-2 rtl:space-x-reverse ">
|
|
20
|
+
<div>
|
|
21
|
+
<label for="code-1" class="sr-only">First code</label>
|
|
22
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-next="code-2" id="code-1" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
23
|
+
</div>
|
|
24
|
+
<div>
|
|
25
|
+
<label for="code-2" class="sr-only">Second code</label>
|
|
26
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-1" data-focus-input-next="code-3" id="code-2" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
27
|
+
</div>
|
|
28
|
+
<div>
|
|
29
|
+
<label for="code-3" class="sr-only">Third code</label>
|
|
30
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-2" data-focus-input-next="code-4" id="code-3" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
31
|
+
</div>
|
|
32
|
+
<div>
|
|
33
|
+
<label for="code-4" class="sr-only">Fourth code</label>
|
|
34
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-3" data-focus-input-next="code-5" id="code-4" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
35
|
+
</div>
|
|
36
|
+
<div>
|
|
37
|
+
<label for="code-5" class="sr-only">Fifth code</label>
|
|
38
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-4" data-focus-input-next="code-6" id="code-5" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
39
|
+
</div>
|
|
40
|
+
<div>
|
|
41
|
+
<label for="code-6" class="sr-only">Sixth code</label>
|
|
42
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-5" id="code-6" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<p id="helper-text-explanation" class="mt-2 text-sm text-gray-500 dark:text-gray-400"></p>
|
|
46
|
+
</form>
|
|
47
|
+
<button @click="()=>{router.push('./login')}" class="flex items-center justify-center gap-1 w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
|
|
48
|
+
>Cancel</button>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
</template>
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
<script setup>
|
|
61
|
+
|
|
62
|
+
import { onMounted, ref, watchEffect,computed } from 'vue';
|
|
63
|
+
import { useCoreStore } from '@/stores/core';
|
|
64
|
+
import { useUserStore } from '@/stores/user';
|
|
65
|
+
import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
|
|
66
|
+
import { callAdminForthApi, loadFile } from '@/utils';
|
|
67
|
+
import { useRouter } from 'vue-router';
|
|
68
|
+
import { initFlowbite } from 'flowbite'
|
|
69
|
+
import { showErrorTost } from '@/composables/useFrontendApi';
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
const router = useRouter();
|
|
75
|
+
const inProgress = ref(false);
|
|
76
|
+
|
|
77
|
+
const coreStore = useCoreStore();
|
|
78
|
+
const user = useUserStore();
|
|
79
|
+
|
|
80
|
+
// use this simple function to automatically focus on the next input
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
const showPw = ref(false);
|
|
85
|
+
|
|
86
|
+
const error = ref(null);
|
|
87
|
+
const totp = ref({});
|
|
88
|
+
const totpJWT = ref(null);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
function parseJwt(token) {
|
|
92
|
+
// Split the token into its parts
|
|
93
|
+
const base64Url = token.split('.')[1];
|
|
94
|
+
|
|
95
|
+
// Base64-decode the payload
|
|
96
|
+
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
97
|
+
const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
|
|
98
|
+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
99
|
+
}).join(''));
|
|
100
|
+
|
|
101
|
+
// Parse the JSON payload
|
|
102
|
+
return JSON.parse(jsonPayload);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
onMounted(async () => {
|
|
106
|
+
coreStore.getPublicConfig()
|
|
107
|
+
|
|
108
|
+
function focusNextInput(el, prevId, nextId) {
|
|
109
|
+
if (el.value.length === 0) {
|
|
110
|
+
if (prevId) {
|
|
111
|
+
document.getElementById(prevId).focus();
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
if (nextId) {
|
|
115
|
+
document.getElementById(nextId).focus();
|
|
116
|
+
} else {
|
|
117
|
+
sendCode()
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
document.querySelectorAll('[data-focus-input-init]').forEach(function(element) {
|
|
123
|
+
element.addEventListener('keyup', function() {
|
|
124
|
+
const prevId = this.getAttribute('data-focus-input-prev');
|
|
125
|
+
const nextId = this.getAttribute('data-focus-input-next');
|
|
126
|
+
focusNextInput(this, prevId, nextId);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
async function sendCode () {
|
|
135
|
+
inProgress.value = true;
|
|
136
|
+
const code = document.getElementById('code-1').value + document.getElementById('code-2').value + document.getElementById('code-3').value + document.getElementById('code-4').value + document.getElementById('code-5').value + document.getElementById('code-6').value;
|
|
137
|
+
const resp = await callAdminForthApi({
|
|
138
|
+
method: 'POST',
|
|
139
|
+
path: '/plugin/twofa/confirmSetup',
|
|
140
|
+
body: {
|
|
141
|
+
code: code,
|
|
142
|
+
secret: null,
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
if (resp.allowedLogin){
|
|
146
|
+
router.push('/');
|
|
147
|
+
} else {
|
|
148
|
+
showErrorTost('Invalid code');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
</script>
|
|
152
|
+
|
|
File without changes
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="relative flex items-center justify-center min-h-screen bg-gray-100 dark:bg-gray-800"
|
|
3
|
+
:style="coreStore.config?.loginBackgroundImage ? {
|
|
4
|
+
'background-image': 'url(' + loadFile(coreStore.config?.loginBackgroundImage) + ')',
|
|
5
|
+
'background-size': 'cover',
|
|
6
|
+
'background-position': 'center',
|
|
7
|
+
'background-blend-mode': 'darken'
|
|
8
|
+
}: {}"
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
<div id="authentication-modal" tabindex="-1" class=" overflow-y-auto overflow-x-hidden z-50 min-w-[00px] justify-center items-center md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
|
12
|
+
<div class="relative p-4 w-full max-w-md max-h-full">
|
|
13
|
+
<!-- Modal content -->
|
|
14
|
+
<div class="relative bg-white rounded-lg shadow dark:bg-gray-700 dark:shadow-black text-gray-500" >
|
|
15
|
+
<div class="p-8 w-full max-w-md max-h-full" >
|
|
16
|
+
<div class="m-3" >Scan this QR code with your authenticator app or open by <a class="text-blue-600" :href="totpUri">click</a></div>
|
|
17
|
+
<div class="flex justify-center m-3" >
|
|
18
|
+
<img :src="totpQrCode" alt="QR code" />
|
|
19
|
+
</div>
|
|
20
|
+
<div class="m-3 ">
|
|
21
|
+
<div class="m-1">Or copy this code to app manually:</div>
|
|
22
|
+
<div class="w-full max-w-[46rem]">
|
|
23
|
+
<div class="relative">
|
|
24
|
+
<label for="npm-install-copy-text" class="sr-only">Label</label>
|
|
25
|
+
<input id="npm-install-copy-text" type="text" class="col-span-10 bg-gray-50 border border-gray-300 text-gray-500 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full px-2.5 py-4 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-gray-400 dark:focus:ring-blue-500 dark:focus:border-blue-500" :value="totp.newSecret" disabled readonly>
|
|
26
|
+
<button data-copy-to-clipboard-target="npm-install-copy-text" class="absolute end-2.5 top-1/2 -translate-y-1/2 text-gray-900 dark:text-gray-400 hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-600 dark:hover:bg-gray-700 rounded-lg py-2 px-2.5 inline-flex items-center justify-center bg-white border-gray-200 border">
|
|
27
|
+
<span id="default-message" class="inline-flex items-center">
|
|
28
|
+
<svg class="w-3 h-3 me-1.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 18 20">
|
|
29
|
+
<path d="M16 1h-3.278A1.992 1.992 0 0 0 11 0H7a1.993 1.993 0 0 0-1.722 1H2a2 2 0 0 0-2 2v15a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2Zm-3 14H5a1 1 0 0 1 0-2h8a1 1 0 0 1 0 2Zm0-4H5a1 1 0 0 1 0-2h8a1 1 0 1 1 0 2Zm0-5H5a1 1 0 0 1 0-2h2V2h4v2h2a1 1 0 1 1 0 2Z"/>
|
|
30
|
+
</svg>
|
|
31
|
+
<span class="text-xs font-semibold">Copy</span>
|
|
32
|
+
</span>
|
|
33
|
+
<span id="success-message" class="hidden inline-flex items-center">
|
|
34
|
+
<svg class="w-3 h-3 text-blue-700 dark:text-blue-500 me-1.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 12">
|
|
35
|
+
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5.917 5.724 10.5 15 1.5"/>
|
|
36
|
+
</svg>
|
|
37
|
+
<span class="text-xs font-semibold text-blue-700 dark:text-blue-500">Copied</span>
|
|
38
|
+
</span>
|
|
39
|
+
</button>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
<form class="max-w-sm mx-auto mt-6 flex flex-col items-center ">
|
|
44
|
+
<div class="flex mb-2 space-x-2 rtl:space-x-reverse ">
|
|
45
|
+
<div>
|
|
46
|
+
<label for="code-1" class="sr-only">First code</label>
|
|
47
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-next="code-2" id="code-1" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
48
|
+
</div>
|
|
49
|
+
<div>
|
|
50
|
+
<label for="code-2" class="sr-only">Second code</label>
|
|
51
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-1" data-focus-input-next="code-3" id="code-2" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
52
|
+
</div>
|
|
53
|
+
<div>
|
|
54
|
+
<label for="code-3" class="sr-only">Third code</label>
|
|
55
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-2" data-focus-input-next="code-4" id="code-3" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
56
|
+
</div>
|
|
57
|
+
<div>
|
|
58
|
+
<label for="code-4" class="sr-only">Fourth code</label>
|
|
59
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-3" data-focus-input-next="code-5" id="code-4" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
60
|
+
</div>
|
|
61
|
+
<div>
|
|
62
|
+
<label for="code-5" class="sr-only">Fifth code</label>
|
|
63
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-4" data-focus-input-next="code-6" id="code-5" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
64
|
+
</div>
|
|
65
|
+
<div>
|
|
66
|
+
<label for="code-6" class="sr-only">Sixth code</label>
|
|
67
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-5" id="code-6" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
<p id="helper-text-explanation" class="mt-2 text-sm text-gray-500 dark:text-gray-400"></p>
|
|
71
|
+
</form>
|
|
72
|
+
<button @click="()=>{router.push('./login')}" class="flex items-center justify-center gap-1 w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Cancel</button>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
</template>
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
<script setup>
|
|
85
|
+
|
|
86
|
+
import { onMounted, ref, watchEffect,computed } from 'vue';
|
|
87
|
+
import { useCoreStore } from '@/stores/core';
|
|
88
|
+
import { useUserStore } from '@/stores/user';
|
|
89
|
+
import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
|
|
90
|
+
import { callAdminForthApi, loadFile } from '@/utils';
|
|
91
|
+
import { useRouter } from 'vue-router';
|
|
92
|
+
import { initFlowbite } from 'flowbite'
|
|
93
|
+
import { showErrorTost } from '@/composables/useFrontendApi';
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
const router = useRouter();
|
|
99
|
+
const inProgress = ref(false);
|
|
100
|
+
|
|
101
|
+
const coreStore = useCoreStore();
|
|
102
|
+
const user = useUserStore();
|
|
103
|
+
|
|
104
|
+
// use this simple function to automatically focus on the next input
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
const showPw = ref(false);
|
|
109
|
+
|
|
110
|
+
const error = ref(null);
|
|
111
|
+
const totp = ref({});
|
|
112
|
+
const totpJWT = ref(null);
|
|
113
|
+
const totpUri = computed(() => {
|
|
114
|
+
if (totp.value) {
|
|
115
|
+
return `otpauth://totp/${totp.value.issuer}:${totp.value.userName}?secret=${totp.value.newSecret}&issuer=${totp.value.issuer}`;
|
|
116
|
+
}});
|
|
117
|
+
const totpQrCode = computed(() => {
|
|
118
|
+
if (totpUri.value) {
|
|
119
|
+
return `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(totpUri.value)}`;
|
|
120
|
+
}});
|
|
121
|
+
|
|
122
|
+
function parseJwt(token) {
|
|
123
|
+
// Split the token into its parts
|
|
124
|
+
const base64Url = token.split('.')[1];
|
|
125
|
+
|
|
126
|
+
// Base64-decode the payload
|
|
127
|
+
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
128
|
+
const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
|
|
129
|
+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
130
|
+
}).join(''));
|
|
131
|
+
|
|
132
|
+
// Parse the JSON payload
|
|
133
|
+
return JSON.parse(jsonPayload);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
onMounted(async () => {
|
|
137
|
+
coreStore.getPublicConfig()
|
|
138
|
+
const resp = await callAdminForthApi({
|
|
139
|
+
path: '/plugin/twofa/initSetup',
|
|
140
|
+
method: 'POST',});
|
|
141
|
+
if (resp && resp.totpJWT){
|
|
142
|
+
totpJWT.value = resp.totpJWT;
|
|
143
|
+
}
|
|
144
|
+
function focusNextInput(el, prevId, nextId) {
|
|
145
|
+
if (el.value.length === 0) {
|
|
146
|
+
if (prevId) {
|
|
147
|
+
document.getElementById(prevId).focus();
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
if (nextId) {
|
|
151
|
+
document.getElementById(nextId).focus();
|
|
152
|
+
} else {
|
|
153
|
+
sendCode()
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
document.querySelectorAll('[data-focus-input-init]').forEach(function(element) {
|
|
159
|
+
element.addEventListener('keyup', function() {
|
|
160
|
+
const prevId = this.getAttribute('data-focus-input-prev');
|
|
161
|
+
const nextId = this.getAttribute('data-focus-input-next');
|
|
162
|
+
focusNextInput(this, prevId, nextId);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
totp.value=parseJwt(totpJWT.value);
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
async function sendCode () {
|
|
172
|
+
inProgress.value = true;
|
|
173
|
+
const code = document.getElementById('code-1').value + document.getElementById('code-2').value + document.getElementById('code-3').value + document.getElementById('code-4').value + document.getElementById('code-5').value + document.getElementById('code-6').value;
|
|
174
|
+
const resp = await callAdminForthApi({
|
|
175
|
+
method: 'POST',
|
|
176
|
+
path: '/plugin/twofa/confirmSetup',
|
|
177
|
+
body: {
|
|
178
|
+
code: code,
|
|
179
|
+
secret: totp.value.newSecret,
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
if (resp.allowedLogin){
|
|
183
|
+
router.push('/');
|
|
184
|
+
} else {
|
|
185
|
+
showErrorTost('Invalid code');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
</script>
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="relative flex items-center justify-center min-h-screen bg-gray-100 dark:bg-gray-800"
|
|
3
|
+
:style="coreStore.config?.loginBackgroundImage ? {
|
|
4
|
+
'background-image': 'url(' + loadFile(coreStore.config?.loginBackgroundImage) + ')',
|
|
5
|
+
'background-size': 'cover',
|
|
6
|
+
'background-position': 'center',
|
|
7
|
+
'background-blend-mode': 'darken'
|
|
8
|
+
}: {}"
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
<div id="authentication-modal" tabindex="-1" class=" overflow-y-auto overflow-x-hidden z-50 min-w-[00px] justify-center items-center md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
|
12
|
+
<div class="relative p-4 w-full max-w-md max-h-full">
|
|
13
|
+
<!-- Modal content -->
|
|
14
|
+
<div class="relative bg-white rounded-lg shadow dark:bg-gray-700 dark:shadow-black text-gray-500" >
|
|
15
|
+
<div class="p-8 w-full max-w-md max-h-full" >
|
|
16
|
+
<div class="m-3" >Please enter your authenticator code </div>
|
|
17
|
+
|
|
18
|
+
<form class="max-w-sm mx-auto mt-6 flex flex-col items-center ">
|
|
19
|
+
<div class="flex mb-2 space-x-2 rtl:space-x-reverse ">
|
|
20
|
+
<div>
|
|
21
|
+
<label for="code-1" class="sr-only">First code</label>
|
|
22
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-next="code-2" id="code-1" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
23
|
+
</div>
|
|
24
|
+
<div>
|
|
25
|
+
<label for="code-2" class="sr-only">Second code</label>
|
|
26
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-1" data-focus-input-next="code-3" id="code-2" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
27
|
+
</div>
|
|
28
|
+
<div>
|
|
29
|
+
<label for="code-3" class="sr-only">Third code</label>
|
|
30
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-2" data-focus-input-next="code-4" id="code-3" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
31
|
+
</div>
|
|
32
|
+
<div>
|
|
33
|
+
<label for="code-4" class="sr-only">Fourth code</label>
|
|
34
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-3" data-focus-input-next="code-5" id="code-4" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
35
|
+
</div>
|
|
36
|
+
<div>
|
|
37
|
+
<label for="code-5" class="sr-only">Fifth code</label>
|
|
38
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-4" data-focus-input-next="code-6" id="code-5" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
39
|
+
</div>
|
|
40
|
+
<div>
|
|
41
|
+
<label for="code-6" class="sr-only">Sixth code</label>
|
|
42
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-5" id="code-6" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<p id="helper-text-explanation" class="mt-2 text-sm text-gray-500 dark:text-gray-400"></p>
|
|
46
|
+
</form>
|
|
47
|
+
<button @click="()=>{router.push('./login')}" class="flex items-center justify-center gap-1 w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
|
|
48
|
+
>Cancel</button>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
</template>
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
<script setup>
|
|
61
|
+
|
|
62
|
+
import { onMounted, ref, watchEffect,computed } from 'vue';
|
|
63
|
+
import { useCoreStore } from '@/stores/core';
|
|
64
|
+
import { useUserStore } from '@/stores/user';
|
|
65
|
+
import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
|
|
66
|
+
import { callAdminForthApi, loadFile } from '@/utils';
|
|
67
|
+
import { useRouter } from 'vue-router';
|
|
68
|
+
import { initFlowbite } from 'flowbite'
|
|
69
|
+
import { showErrorTost } from '@/composables/useFrontendApi';
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
const router = useRouter();
|
|
75
|
+
const inProgress = ref(false);
|
|
76
|
+
|
|
77
|
+
const coreStore = useCoreStore();
|
|
78
|
+
const user = useUserStore();
|
|
79
|
+
|
|
80
|
+
// use this simple function to automatically focus on the next input
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
const showPw = ref(false);
|
|
85
|
+
|
|
86
|
+
const error = ref(null);
|
|
87
|
+
const totp = ref({});
|
|
88
|
+
const totpJWT = ref(null);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
function parseJwt(token) {
|
|
92
|
+
// Split the token into its parts
|
|
93
|
+
const base64Url = token.split('.')[1];
|
|
94
|
+
|
|
95
|
+
// Base64-decode the payload
|
|
96
|
+
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
97
|
+
const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
|
|
98
|
+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
99
|
+
}).join(''));
|
|
100
|
+
|
|
101
|
+
// Parse the JSON payload
|
|
102
|
+
return JSON.parse(jsonPayload);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
onMounted(async () => {
|
|
106
|
+
coreStore.getPublicConfig()
|
|
107
|
+
|
|
108
|
+
function focusNextInput(el, prevId, nextId) {
|
|
109
|
+
if (el.value.length === 0) {
|
|
110
|
+
if (prevId) {
|
|
111
|
+
document.getElementById(prevId).focus();
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
if (nextId) {
|
|
115
|
+
document.getElementById(nextId).focus();
|
|
116
|
+
} else {
|
|
117
|
+
sendCode()
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
document.querySelectorAll('[data-focus-input-init]').forEach(function(element) {
|
|
123
|
+
element.addEventListener('keyup', function() {
|
|
124
|
+
const prevId = this.getAttribute('data-focus-input-prev');
|
|
125
|
+
const nextId = this.getAttribute('data-focus-input-next');
|
|
126
|
+
focusNextInput(this, prevId, nextId);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
async function sendCode () {
|
|
135
|
+
inProgress.value = true;
|
|
136
|
+
const code = document.getElementById('code-1').value + document.getElementById('code-2').value + document.getElementById('code-3').value + document.getElementById('code-4').value + document.getElementById('code-5').value + document.getElementById('code-6').value;
|
|
137
|
+
const resp = await callAdminForthApi({
|
|
138
|
+
method: 'POST',
|
|
139
|
+
path: '/plugin/twofa/confirmSetup',
|
|
140
|
+
body: {
|
|
141
|
+
code: code,
|
|
142
|
+
secret: null,
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
if (resp.allowedLogin){
|
|
146
|
+
router.push('/');
|
|
147
|
+
} else {
|
|
148
|
+
showErrorTost('Invalid code');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
</script>
|
|
152
|
+
|
|
File without changes
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="relative flex items-center justify-center min-h-screen bg-gray-100 dark:bg-gray-800"
|
|
3
|
+
:style="coreStore.config?.loginBackgroundImage ? {
|
|
4
|
+
'background-image': 'url(' + loadFile(coreStore.config?.loginBackgroundImage) + ')',
|
|
5
|
+
'background-size': 'cover',
|
|
6
|
+
'background-position': 'center',
|
|
7
|
+
'background-blend-mode': 'darken'
|
|
8
|
+
}: {}"
|
|
9
|
+
>
|
|
10
|
+
|
|
11
|
+
<div id="authentication-modal" tabindex="-1" class=" overflow-y-auto overflow-x-hidden z-50 min-w-[00px] justify-center items-center md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
|
12
|
+
<div class="relative p-4 w-full max-w-md max-h-full">
|
|
13
|
+
<!-- Modal content -->
|
|
14
|
+
<div class="relative bg-white rounded-lg shadow dark:bg-gray-700 dark:shadow-black text-gray-500" >
|
|
15
|
+
<div class="p-8 w-full max-w-md max-h-full" >
|
|
16
|
+
<div class="m-3" >Scan this QR code with your authenticator app or open by <a class="text-blue-600" :href="totpUri">click</a></div>
|
|
17
|
+
<div class="flex justify-center m-3" >
|
|
18
|
+
<img :src="totpQrCode" alt="QR code" />
|
|
19
|
+
</div>
|
|
20
|
+
<div class="m-3 ">
|
|
21
|
+
<div class="m-1">Or copy this code to app manually:</div>
|
|
22
|
+
<div class="w-full max-w-[46rem]">
|
|
23
|
+
<div class="relative">
|
|
24
|
+
<label for="npm-install-copy-text" class="sr-only">Label</label>
|
|
25
|
+
<input id="npm-install-copy-text" type="text" class="col-span-10 bg-gray-50 border border-gray-300 text-gray-500 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full px-2.5 py-4 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-gray-400 dark:focus:ring-blue-500 dark:focus:border-blue-500" :value="totp.newSecret" disabled readonly>
|
|
26
|
+
<button data-copy-to-clipboard-target="npm-install-copy-text" class="absolute end-2.5 top-1/2 -translate-y-1/2 text-gray-900 dark:text-gray-400 hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-600 dark:hover:bg-gray-700 rounded-lg py-2 px-2.5 inline-flex items-center justify-center bg-white border-gray-200 border">
|
|
27
|
+
<span id="default-message" class="inline-flex items-center">
|
|
28
|
+
<svg class="w-3 h-3 me-1.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 18 20">
|
|
29
|
+
<path d="M16 1h-3.278A1.992 1.992 0 0 0 11 0H7a1.993 1.993 0 0 0-1.722 1H2a2 2 0 0 0-2 2v15a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2Zm-3 14H5a1 1 0 0 1 0-2h8a1 1 0 0 1 0 2Zm0-4H5a1 1 0 0 1 0-2h8a1 1 0 1 1 0 2Zm0-5H5a1 1 0 0 1 0-2h2V2h4v2h2a1 1 0 1 1 0 2Z"/>
|
|
30
|
+
</svg>
|
|
31
|
+
<span class="text-xs font-semibold">Copy</span>
|
|
32
|
+
</span>
|
|
33
|
+
<span id="success-message" class="hidden inline-flex items-center">
|
|
34
|
+
<svg class="w-3 h-3 text-blue-700 dark:text-blue-500 me-1.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 12">
|
|
35
|
+
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5.917 5.724 10.5 15 1.5"/>
|
|
36
|
+
</svg>
|
|
37
|
+
<span class="text-xs font-semibold text-blue-700 dark:text-blue-500">Copied</span>
|
|
38
|
+
</span>
|
|
39
|
+
</button>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
<form class="max-w-sm mx-auto mt-6 flex flex-col items-center ">
|
|
44
|
+
<div class="flex mb-2 space-x-2 rtl:space-x-reverse ">
|
|
45
|
+
<div>
|
|
46
|
+
<label for="code-1" class="sr-only">First code</label>
|
|
47
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-next="code-2" id="code-1" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
48
|
+
</div>
|
|
49
|
+
<div>
|
|
50
|
+
<label for="code-2" class="sr-only">Second code</label>
|
|
51
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-1" data-focus-input-next="code-3" id="code-2" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
52
|
+
</div>
|
|
53
|
+
<div>
|
|
54
|
+
<label for="code-3" class="sr-only">Third code</label>
|
|
55
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-2" data-focus-input-next="code-4" id="code-3" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
56
|
+
</div>
|
|
57
|
+
<div>
|
|
58
|
+
<label for="code-4" class="sr-only">Fourth code</label>
|
|
59
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-3" data-focus-input-next="code-5" id="code-4" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
60
|
+
</div>
|
|
61
|
+
<div>
|
|
62
|
+
<label for="code-5" class="sr-only">Fifth code</label>
|
|
63
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-4" data-focus-input-next="code-6" id="code-5" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
64
|
+
</div>
|
|
65
|
+
<div>
|
|
66
|
+
<label for="code-6" class="sr-only">Sixth code</label>
|
|
67
|
+
<input type="text" maxlength="1" data-focus-input-init data-focus-input-prev="code-5" id="code-6" class="block w-9 h-9 py-3 text-sm font-extrabold text-center text-gray-900 bg-white border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500" required />
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
<p id="helper-text-explanation" class="mt-2 text-sm text-gray-500 dark:text-gray-400"></p>
|
|
71
|
+
</form>
|
|
72
|
+
<button @click="()=>{router.push('./login')}" class="flex items-center justify-center gap-1 w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Cancel</button>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
</template>
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
<script setup>
|
|
85
|
+
|
|
86
|
+
import { onMounted, ref, watchEffect,computed } from 'vue';
|
|
87
|
+
import { useCoreStore } from '@/stores/core';
|
|
88
|
+
import { useUserStore } from '@/stores/user';
|
|
89
|
+
import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
|
|
90
|
+
import { callAdminForthApi, loadFile } from '@/utils';
|
|
91
|
+
import { useRouter } from 'vue-router';
|
|
92
|
+
import { initFlowbite } from 'flowbite'
|
|
93
|
+
import { showErrorTost } from '@/composables/useFrontendApi';
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
const router = useRouter();
|
|
99
|
+
const inProgress = ref(false);
|
|
100
|
+
|
|
101
|
+
const coreStore = useCoreStore();
|
|
102
|
+
const user = useUserStore();
|
|
103
|
+
|
|
104
|
+
// use this simple function to automatically focus on the next input
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
const showPw = ref(false);
|
|
109
|
+
|
|
110
|
+
const error = ref(null);
|
|
111
|
+
const totp = ref({});
|
|
112
|
+
const totpJWT = ref(null);
|
|
113
|
+
const totpUri = computed(() => {
|
|
114
|
+
if (totp.value) {
|
|
115
|
+
return `otpauth://totp/${totp.value.issuer}:${totp.value.userName}?secret=${totp.value.newSecret}&issuer=${totp.value.issuer}`;
|
|
116
|
+
}});
|
|
117
|
+
const totpQrCode = computed(() => {
|
|
118
|
+
if (totpUri.value) {
|
|
119
|
+
return `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(totpUri.value)}`;
|
|
120
|
+
}});
|
|
121
|
+
|
|
122
|
+
function parseJwt(token) {
|
|
123
|
+
// Split the token into its parts
|
|
124
|
+
const base64Url = token.split('.')[1];
|
|
125
|
+
|
|
126
|
+
// Base64-decode the payload
|
|
127
|
+
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
128
|
+
const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
|
|
129
|
+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
130
|
+
}).join(''));
|
|
131
|
+
|
|
132
|
+
// Parse the JSON payload
|
|
133
|
+
return JSON.parse(jsonPayload);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
onMounted(async () => {
|
|
137
|
+
coreStore.getPublicConfig()
|
|
138
|
+
const resp = await callAdminForthApi({
|
|
139
|
+
path: '/plugin/twofa/initSetup',
|
|
140
|
+
method: 'POST',});
|
|
141
|
+
if (resp && resp.totpJWT){
|
|
142
|
+
totpJWT.value = resp.totpJWT;
|
|
143
|
+
}
|
|
144
|
+
function focusNextInput(el, prevId, nextId) {
|
|
145
|
+
if (el.value.length === 0) {
|
|
146
|
+
if (prevId) {
|
|
147
|
+
document.getElementById(prevId).focus();
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
if (nextId) {
|
|
151
|
+
document.getElementById(nextId).focus();
|
|
152
|
+
} else {
|
|
153
|
+
sendCode()
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
document.querySelectorAll('[data-focus-input-init]').forEach(function(element) {
|
|
159
|
+
element.addEventListener('keyup', function() {
|
|
160
|
+
const prevId = this.getAttribute('data-focus-input-prev');
|
|
161
|
+
const nextId = this.getAttribute('data-focus-input-next');
|
|
162
|
+
focusNextInput(this, prevId, nextId);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
totp.value=parseJwt(totpJWT.value);
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
async function sendCode () {
|
|
172
|
+
inProgress.value = true;
|
|
173
|
+
const code = document.getElementById('code-1').value + document.getElementById('code-2').value + document.getElementById('code-3').value + document.getElementById('code-4').value + document.getElementById('code-5').value + document.getElementById('code-6').value;
|
|
174
|
+
const resp = await callAdminForthApi({
|
|
175
|
+
method: 'POST',
|
|
176
|
+
path: '/plugin/twofa/confirmSetup',
|
|
177
|
+
body: {
|
|
178
|
+
code: code,
|
|
179
|
+
secret: totp.value.newSecret,
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
if (resp.allowedLogin){
|
|
183
|
+
router.push('/');
|
|
184
|
+
} else {
|
|
185
|
+
showErrorTost('Invalid code');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
</script>
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { AdminForthPlugin } from "adminforth";
|
|
11
|
+
import twofactor from 'node-2fa';
|
|
12
|
+
export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(options, import.meta.url);
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
modifyResourceConfig(adminforth, resourceConfig) {
|
|
18
|
+
super.modifyResourceConfig(adminforth, resourceConfig);
|
|
19
|
+
this.adminforth = adminforth;
|
|
20
|
+
this.adminForthAuth = adminforth.auth;
|
|
21
|
+
const customPages = this.adminforth.config.customization.customPages;
|
|
22
|
+
customPages.push({
|
|
23
|
+
path: '/confirm2fa',
|
|
24
|
+
component: { file: this.componentPath('TwoFactorsConfirmation.vue'), meta: { customLayout: true } }
|
|
25
|
+
});
|
|
26
|
+
customPages.push({
|
|
27
|
+
path: '/setup2fa',
|
|
28
|
+
component: { file: this.componentPath('TwoFactorsSetup.vue'), meta: { title: 'Setup 2FA', customLayout: true } }
|
|
29
|
+
});
|
|
30
|
+
this.activate(resourceConfig, adminforth);
|
|
31
|
+
}
|
|
32
|
+
activate(resourceConfig, adminforth) {
|
|
33
|
+
if (!this.options.twoFaSecretFieldName) {
|
|
34
|
+
throw new Error('twoFaSecretFieldName is required');
|
|
35
|
+
}
|
|
36
|
+
if (typeof this.options.twoFaSecretFieldName !== 'string') {
|
|
37
|
+
throw new Error('twoFaSecretFieldName must be a string');
|
|
38
|
+
}
|
|
39
|
+
this.authResource = resourceConfig;
|
|
40
|
+
if (!this.authResource.columns.some((col) => col.name === this.options.twoFaSecretFieldName)) {
|
|
41
|
+
throw new Error(`Column ${this.options.twoFaSecretFieldName} not found in ${this.authResource.label}`);
|
|
42
|
+
}
|
|
43
|
+
this.adminforth.config.auth.beforeLoginConfirmation.push((_a) => __awaiter(this, [_a], void 0, function* ({ adminUser, response }) {
|
|
44
|
+
if (adminUser.isRoot) {
|
|
45
|
+
return { body: { loginAllowed: true }, ok: true };
|
|
46
|
+
}
|
|
47
|
+
const secret = adminUser.dbUser[this.options.twoFaSecretFieldName];
|
|
48
|
+
const userName = adminUser.dbUser[adminforth.config.auth.usernameField];
|
|
49
|
+
const brandName = adminforth.config.customization.brandName;
|
|
50
|
+
const authResource = adminforth.config.resources.find((res) => res.resourceId === adminforth.config.auth.resourceId);
|
|
51
|
+
const authPk = authResource.columns.find((col) => col.primaryKey).name;
|
|
52
|
+
const userPk = adminUser.dbUser[authPk];
|
|
53
|
+
let newSecret = null;
|
|
54
|
+
if (!secret) {
|
|
55
|
+
const tempSecret = twofactor.generateSecret({ name: brandName, account: userName });
|
|
56
|
+
newSecret = tempSecret.secret;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const value = this.adminforth.auth.issueJWT({ userName, issuer: brandName, pk: userPk }, 'tempTotp');
|
|
60
|
+
response.setHeader('Set-Cookie', `adminforth_totpTemporaryJWT=${value}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${new Date(Date.now() + '1h').toUTCString()} `);
|
|
61
|
+
return {
|
|
62
|
+
body: {
|
|
63
|
+
loginAllowed: false,
|
|
64
|
+
redirectTo: '/confirm2fa',
|
|
65
|
+
},
|
|
66
|
+
ok: true
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const totpTemporaryJWT = this.adminforth.auth.issueJWT({ userName, newSecret, issuer: brandName, pk: userPk }, 'tempTotp');
|
|
70
|
+
response.setHeader('Set-Cookie', `adminforth_totpTemporaryJWT=${totpTemporaryJWT}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${new Date(Date.now() + '1h').toUTCString()} `);
|
|
71
|
+
return {
|
|
72
|
+
body: {
|
|
73
|
+
loginAllowed: false,
|
|
74
|
+
redirectTo: secret ? '/confirm2fa' : '/setup2fa',
|
|
75
|
+
},
|
|
76
|
+
ok: true
|
|
77
|
+
};
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
setupEndpoints(server) {
|
|
81
|
+
server.endpoint({
|
|
82
|
+
method: 'POST',
|
|
83
|
+
path: `/plugin/twofa/initSetup`,
|
|
84
|
+
noAuth: true,
|
|
85
|
+
handler: (server) => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const toReturn = { totpJWT: null, status: 'ok', };
|
|
87
|
+
const totpTemporaryJWT = server.cookies['adminforth_totpTemporaryJWT'];
|
|
88
|
+
if (totpTemporaryJWT) {
|
|
89
|
+
toReturn.totpJWT = totpTemporaryJWT;
|
|
90
|
+
}
|
|
91
|
+
return toReturn;
|
|
92
|
+
})
|
|
93
|
+
});
|
|
94
|
+
server.endpoint({
|
|
95
|
+
method: 'POST',
|
|
96
|
+
path: `/plugin/twofa/confirmSetup`,
|
|
97
|
+
noAuth: true,
|
|
98
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response, cookies }) {
|
|
99
|
+
const totpTemporaryJWT = cookies['adminforth_totpTemporaryJWT'];
|
|
100
|
+
const decoded = yield this.adminforth.auth.verify(totpTemporaryJWT, 'tempTotp');
|
|
101
|
+
if (!decoded) {
|
|
102
|
+
return { status: 'error', message: 'Invalid token' };
|
|
103
|
+
}
|
|
104
|
+
if (decoded.newSecret) {
|
|
105
|
+
const verified = twofactor.verifyToken(decoded.newSecret, body.code);
|
|
106
|
+
if (verified) {
|
|
107
|
+
this.connectors = this.adminforth.connectors;
|
|
108
|
+
const connector = this.connectors[this.authResource.dataSource];
|
|
109
|
+
yield connector.updateRecord({ resource: this.authResource, recordId: decoded.pk, newValues: { [this.options.twoFaSecretFieldName]: decoded.newSecret } });
|
|
110
|
+
this.adminForthAuth.removeCustomCookie({ response, name: 'totpTemporaryJWT' });
|
|
111
|
+
this.adminForthAuth.setAuthCookie({ response, username: decoded.userName, pk: decoded.pk });
|
|
112
|
+
return { status: 'ok', allowedLogin: true };
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return { error: 'Wrong or expired OTP code' };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// user already has secret, get it
|
|
120
|
+
this.connectors = this.adminforth.connectors;
|
|
121
|
+
const connector = this.connectors[this.authResource.dataSource];
|
|
122
|
+
const user = yield connector.getRecordByPrimaryKey(this.authResource, decoded.pk);
|
|
123
|
+
const verified = twofactor.verifyToken(user[this.options.twoFaSecretFieldName], body.code);
|
|
124
|
+
if (verified) {
|
|
125
|
+
this.adminForthAuth.removeCustomCookie({ response, name: 'totpTemporaryJWT' });
|
|
126
|
+
this.adminForthAuth.setAuthCookie({ response, username: decoded.userName, pk: decoded.pk });
|
|
127
|
+
return { status: 'ok', allowedLogin: true };
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
return { error: 'Wrong or expired OTP code' };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { AdminForthPlugin } from "adminforth";
|
|
2
|
+
import type { AdminForthResource, AdminUser, IAdminForth, IHttpServer, IAdminForthAuth, BeforeLoginConfirmationFunction, IAdminForthHttpResponse } from "adminforth";
|
|
3
|
+
import twofactor from 'node-2fa';
|
|
4
|
+
import { PluginOptions } from "./types.js"
|
|
5
|
+
|
|
6
|
+
export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
7
|
+
options: PluginOptions;
|
|
8
|
+
adminforth: IAdminForth;
|
|
9
|
+
authResource: AdminForthResource;
|
|
10
|
+
connectors: any;
|
|
11
|
+
adminForthAuth: IAdminForthAuth;
|
|
12
|
+
|
|
13
|
+
constructor(options: PluginOptions) {
|
|
14
|
+
super(options, import.meta.url);
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
19
|
+
super.modifyResourceConfig(adminforth, resourceConfig);
|
|
20
|
+
this.adminforth = adminforth;
|
|
21
|
+
this.adminForthAuth = adminforth.auth;
|
|
22
|
+
const customPages = this.adminforth.config.customization.customPages
|
|
23
|
+
customPages.push({
|
|
24
|
+
path:'/confirm2fa',
|
|
25
|
+
component: { file: this.componentPath('TwoFactorsConfirmation.vue'), meta: { customLayout: true }}
|
|
26
|
+
})
|
|
27
|
+
customPages.push({
|
|
28
|
+
path:'/setup2fa',
|
|
29
|
+
component: { file: this.componentPath('TwoFactorsSetup.vue'), meta: { title: 'Setup 2FA', customLayout: true }}
|
|
30
|
+
})
|
|
31
|
+
this.activate( resourceConfig, adminforth )
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
activate ( resourceConfig: AdminForthResource, adminforth: IAdminForth ){
|
|
35
|
+
if (!this.options.twoFaSecretFieldName){
|
|
36
|
+
throw new Error('twoFaSecretFieldName is required')
|
|
37
|
+
}
|
|
38
|
+
if (typeof this.options.twoFaSecretFieldName !=='string'){
|
|
39
|
+
throw new Error('twoFaSecretFieldName must be a string')
|
|
40
|
+
}
|
|
41
|
+
this.authResource = resourceConfig
|
|
42
|
+
if(!this.authResource.columns.some((col)=>col.name === this.options.twoFaSecretFieldName)){
|
|
43
|
+
throw new Error(`Column ${this.options.twoFaSecretFieldName} not found in ${this.authResource.label}`)
|
|
44
|
+
}
|
|
45
|
+
(this.adminforth.config.auth.beforeLoginConfirmation as BeforeLoginConfirmationFunction[]).push(
|
|
46
|
+
async({ adminUser, response }: { adminUser: AdminUser, response: IAdminForthHttpResponse} )=> {
|
|
47
|
+
if(adminUser.isRoot){
|
|
48
|
+
return { body: {loginAllowed: true}, ok: true}
|
|
49
|
+
}
|
|
50
|
+
const secret = adminUser.dbUser[this.options.twoFaSecretFieldName]
|
|
51
|
+
const userName = adminUser.dbUser[adminforth.config.auth.usernameField]
|
|
52
|
+
const brandName = adminforth.config.customization.brandName
|
|
53
|
+
const authResource = adminforth.config.resources.find((res)=>res.resourceId === adminforth.config.auth.resourceId )
|
|
54
|
+
const authPk = authResource.columns.find((col)=>col.primaryKey).name
|
|
55
|
+
const userPk = adminUser.dbUser[authPk]
|
|
56
|
+
let newSecret = null
|
|
57
|
+
if (!secret){
|
|
58
|
+
const tempSecret = twofactor.generateSecret({name: brandName,account: userName})
|
|
59
|
+
newSecret = tempSecret.secret
|
|
60
|
+
} else {
|
|
61
|
+
const value = this.adminforth.auth.issueJWT({userName, issuer:brandName, pk:userPk },'tempTotp');
|
|
62
|
+
response.setHeader('Set-Cookie', `adminforth_totpTemporaryJWT=${value}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${new Date(Date.now() + '1h').toUTCString() } `);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
body:{
|
|
66
|
+
loginAllowed: false,
|
|
67
|
+
redirectTo: '/confirm2fa',
|
|
68
|
+
|
|
69
|
+
},
|
|
70
|
+
ok: true
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const totpTemporaryJWT = this.adminforth.auth.issueJWT({userName, newSecret, issuer:brandName, pk:userPk },'tempTotp', )
|
|
75
|
+
response.setHeader('Set-Cookie', `adminforth_totpTemporaryJWT=${totpTemporaryJWT}; Path=${this.adminforth.config.baseUrl || '/'}; HttpOnly; SameSite=Strict; Expires=${new Date(Date.now() + '1h').toUTCString() } `);
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
body:{
|
|
79
|
+
loginAllowed: false,
|
|
80
|
+
redirectTo: secret ? '/confirm2fa' : '/setup2fa',
|
|
81
|
+
},
|
|
82
|
+
ok: true
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setupEndpoints(server: IHttpServer): void {
|
|
88
|
+
server.endpoint({
|
|
89
|
+
method: 'POST',
|
|
90
|
+
path: `/plugin/twofa/initSetup`,
|
|
91
|
+
noAuth: true,
|
|
92
|
+
handler: async (server) => {
|
|
93
|
+
const toReturn = {totpJWT:null,status:'ok',}
|
|
94
|
+
const totpTemporaryJWT = server.cookies['adminforth_totpTemporaryJWT']
|
|
95
|
+
if (totpTemporaryJWT){
|
|
96
|
+
toReturn.totpJWT = totpTemporaryJWT
|
|
97
|
+
}
|
|
98
|
+
return toReturn
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
server.endpoint({
|
|
102
|
+
method: 'POST',
|
|
103
|
+
path: `/plugin/twofa/confirmSetup`,
|
|
104
|
+
noAuth: true,
|
|
105
|
+
handler: async ({ body, adminUser, response, cookies }) => {
|
|
106
|
+
const totpTemporaryJWT = cookies['adminforth_totpTemporaryJWT']
|
|
107
|
+
const decoded = await this.adminforth.auth.verify(totpTemporaryJWT, 'tempTotp');
|
|
108
|
+
if ( !decoded ) {
|
|
109
|
+
return {status:'error',message:'Invalid token'}
|
|
110
|
+
}
|
|
111
|
+
if (decoded.newSecret) {
|
|
112
|
+
const verified = twofactor.verifyToken(decoded.newSecret, body.code);
|
|
113
|
+
if (verified) {
|
|
114
|
+
this.connectors = this.adminforth.connectors
|
|
115
|
+
const connector = this.connectors[this.authResource.dataSource];
|
|
116
|
+
await connector.updateRecord({resource:this.authResource, recordId:decoded.pk, newValues:{[this.options.twoFaSecretFieldName]: decoded.newSecret}})
|
|
117
|
+
this.adminForthAuth.removeCustomCookie({response, name:'totpTemporaryJWT'})
|
|
118
|
+
this.adminForthAuth.setAuthCookie({response, username:decoded.userName, pk:decoded.pk})
|
|
119
|
+
return { status: 'ok',allowedLogin: true }
|
|
120
|
+
} else {
|
|
121
|
+
return {error: 'Wrong or expired OTP code'}
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
// user already has secret, get it
|
|
125
|
+
this.connectors = this.adminforth.connectors
|
|
126
|
+
const connector = this.connectors[this.authResource.dataSource];
|
|
127
|
+
const user = await connector.getRecordByPrimaryKey(this.authResource, decoded.pk)
|
|
128
|
+
const verified = twofactor.verifyToken(user[this.options.twoFaSecretFieldName], body.code);
|
|
129
|
+
if (verified) {
|
|
130
|
+
this.adminForthAuth.removeCustomCookie({response, name:'totpTemporaryJWT'})
|
|
131
|
+
this.adminForthAuth.setAuthCookie({response, username:decoded.userName, pk:decoded.pk})
|
|
132
|
+
return { status: 'ok',allowedLogin: true }
|
|
133
|
+
} else {
|
|
134
|
+
return {error: 'Wrong or expired OTP code'}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adminforth/two-factors-auth",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "AdminForth plugin for two factors authentication",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"rollout": "tsc && cp -rf custom dist/ && npm version patch && npm publish --access public"
|
|
10
|
+
},
|
|
11
|
+
"author": "devforth",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"node-2fa": "^2.0.3"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/* Language and Environment */
|
|
15
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
16
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
17
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
18
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
19
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
21
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
22
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
25
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
26
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
+
|
|
28
|
+
/* Modules */
|
|
29
|
+
// changed from commmonjs to node16 because The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.
|
|
30
|
+
"module": "node16", /* Specify what module code is generated. */
|
|
31
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
32
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
33
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
34
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
35
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
36
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
37
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
38
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
39
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
40
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
41
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
42
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
43
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
44
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
45
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
46
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
47
|
+
|
|
48
|
+
/* JavaScript Support */
|
|
49
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
50
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
51
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
52
|
+
|
|
53
|
+
/* Emit */
|
|
54
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
55
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
56
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
57
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
58
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
59
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
60
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
61
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
62
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
63
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
64
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
65
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
66
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
67
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
68
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
69
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
70
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
71
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
72
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
73
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
74
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
75
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
76
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
77
|
+
|
|
78
|
+
/* Interop Constraints */
|
|
79
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
80
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
81
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
82
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
83
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
84
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
85
|
+
|
|
86
|
+
/* Type Checking */
|
|
87
|
+
"strict": false, /* TODO */ /* Enable all strict type-checking options. */
|
|
88
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
89
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
90
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
91
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
92
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
93
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
94
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
95
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
96
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
97
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
98
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
99
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
100
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
101
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
102
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
103
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
104
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
105
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
106
|
+
|
|
107
|
+
/* Completeness */
|
|
108
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
109
|
+
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
|
|
110
|
+
},
|
|
111
|
+
"exclude": ["node_modules", "dist", "custom"], /* Exclude files from compilation. */
|
|
112
|
+
}
|
package/types.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type PluginOptions = {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Name of the field in the auth resource which will store 2FA secret.
|
|
5
|
+
*
|
|
6
|
+
* Resource mandatory should have one columns which defined {@link AdminForthResourceColumn} which
|
|
7
|
+
* name should be equal to the value .
|
|
8
|
+
*/
|
|
9
|
+
twoFaSecretFieldName: string;
|
|
10
|
+
}
|