@adminforth/two-factors-auth 1.0.14 → 1.0.16
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.
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
|
|
74
73
|
const router = useRouter();
|
|
75
74
|
const inProgress = ref(false);
|
|
76
75
|
|
|
@@ -143,10 +142,10 @@
|
|
|
143
142
|
}
|
|
144
143
|
})
|
|
145
144
|
if (resp.allowedLogin){
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
145
|
+
await user.finishLogin();
|
|
146
|
+
} else {
|
|
147
|
+
showErrorTost('Invalid code');
|
|
150
148
|
}
|
|
149
|
+
}
|
|
151
150
|
</script>
|
|
152
151
|
|
|
@@ -89,7 +89,6 @@ import { useUserStore } from '@/stores/user';
|
|
|
89
89
|
import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
|
|
90
90
|
import { callAdminForthApi, loadFile } from '@/utils';
|
|
91
91
|
import { useRouter } from 'vue-router';
|
|
92
|
-
import { initFlowbite } from 'flowbite'
|
|
93
92
|
import { showErrorTost } from '@/composables/useFrontendApi';
|
|
94
93
|
|
|
95
94
|
|
|
@@ -180,9 +179,9 @@ async function sendCode () {
|
|
|
180
179
|
}
|
|
181
180
|
})
|
|
182
181
|
if (resp.allowedLogin){
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
182
|
+
await user.finishLogin()
|
|
183
|
+
} else {
|
|
184
|
+
showErrorTost('Invalid code');
|
|
187
185
|
}
|
|
186
|
+
}
|
|
188
187
|
</script>
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
|
|
74
73
|
const router = useRouter();
|
|
75
74
|
const inProgress = ref(false);
|
|
76
75
|
|
|
@@ -143,10 +142,10 @@
|
|
|
143
142
|
}
|
|
144
143
|
})
|
|
145
144
|
if (resp.allowedLogin){
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
145
|
+
await user.finishLogin();
|
|
146
|
+
} else {
|
|
147
|
+
showErrorTost('Invalid code');
|
|
150
148
|
}
|
|
149
|
+
}
|
|
151
150
|
</script>
|
|
152
151
|
|
|
@@ -89,7 +89,6 @@ import { useUserStore } from '@/stores/user';
|
|
|
89
89
|
import { IconEyeSolid, IconEyeSlashSolid } from '@iconify-prerendered/vue-flowbite';
|
|
90
90
|
import { callAdminForthApi, loadFile } from '@/utils';
|
|
91
91
|
import { useRouter } from 'vue-router';
|
|
92
|
-
import { initFlowbite } from 'flowbite'
|
|
93
92
|
import { showErrorTost } from '@/composables/useFrontendApi';
|
|
94
93
|
|
|
95
94
|
|
|
@@ -180,9 +179,9 @@ async function sendCode () {
|
|
|
180
179
|
}
|
|
181
180
|
})
|
|
182
181
|
if (resp.allowedLogin){
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
182
|
+
await user.finishLogin()
|
|
183
|
+
} else {
|
|
184
|
+
showErrorTost('Invalid code');
|
|
187
185
|
}
|
|
186
|
+
}
|
|
188
187
|
</script>
|
package/dist/index.js
CHANGED
|
@@ -97,7 +97,8 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
97
97
|
path: `/plugin/twofa/confirmSetup`,
|
|
98
98
|
noAuth: true,
|
|
99
99
|
handler: (_b) => __awaiter(this, [_b], void 0, function* ({ body, adminUser, response, cookies }) {
|
|
100
|
-
|
|
100
|
+
var _c;
|
|
101
|
+
const totpTemporaryJWT = (_c = cookies.find((cookie) => cookie.key === 'adminforth_totpTemporaryJWT')) === null || _c === void 0 ? void 0 : _c.value;
|
|
101
102
|
const decoded = yield this.adminforth.auth.verify(totpTemporaryJWT, 'tempTotp');
|
|
102
103
|
if (!decoded) {
|
|
103
104
|
return { status: 'error', message: 'Invalid token' };
|
|
@@ -108,8 +109,8 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
108
109
|
this.connectors = this.adminforth.connectors;
|
|
109
110
|
const connector = this.connectors[this.authResource.dataSource];
|
|
110
111
|
yield connector.updateRecord({ resource: this.authResource, recordId: decoded.pk, newValues: { [this.options.twoFaSecretFieldName]: decoded.newSecret } });
|
|
111
|
-
this.
|
|
112
|
-
this.
|
|
112
|
+
this.adminforth.auth.removeCustomCookie({ response, name: 'totpTemporaryJWT' });
|
|
113
|
+
this.adminforth.auth.setAuthCookie({ response, username: decoded.userName, pk: decoded.pk });
|
|
113
114
|
return { status: 'ok', allowedLogin: true };
|
|
114
115
|
}
|
|
115
116
|
else {
|
|
@@ -123,8 +124,8 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
123
124
|
const user = yield connector.getRecordByPrimaryKey(this.authResource, decoded.pk);
|
|
124
125
|
const verified = twofactor.verifyToken(user[this.options.twoFaSecretFieldName], body.code);
|
|
125
126
|
if (verified) {
|
|
126
|
-
this.
|
|
127
|
-
this.
|
|
127
|
+
this.adminforth.auth.removeCustomCookie({ response, name: 'totpTemporaryJWT' });
|
|
128
|
+
this.adminforth.auth.setAuthCookie({ response, username: decoded.userName, pk: decoded.pk });
|
|
128
129
|
return { status: 'ok', allowedLogin: true };
|
|
129
130
|
}
|
|
130
131
|
else {
|
package/index.ts
CHANGED
|
@@ -104,7 +104,7 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
104
104
|
path: `/plugin/twofa/confirmSetup`,
|
|
105
105
|
noAuth: true,
|
|
106
106
|
handler: async ({ body, adminUser, response, cookies }) => {
|
|
107
|
-
const totpTemporaryJWT = cookies
|
|
107
|
+
const totpTemporaryJWT = cookies.find((cookie)=>cookie.key === 'adminforth_totpTemporaryJWT')?.value;
|
|
108
108
|
const decoded = await this.adminforth.auth.verify(totpTemporaryJWT, 'tempTotp');
|
|
109
109
|
if ( !decoded ) {
|
|
110
110
|
return {status:'error',message:'Invalid token'}
|
|
@@ -115,9 +115,9 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
115
115
|
this.connectors = this.adminforth.connectors
|
|
116
116
|
const connector = this.connectors[this.authResource.dataSource];
|
|
117
117
|
await connector.updateRecord({resource:this.authResource, recordId:decoded.pk, newValues:{[this.options.twoFaSecretFieldName]: decoded.newSecret}})
|
|
118
|
-
this.
|
|
119
|
-
this.
|
|
120
|
-
return { status: 'ok',allowedLogin: true }
|
|
118
|
+
this.adminforth.auth.removeCustomCookie({response, name:'totpTemporaryJWT'})
|
|
119
|
+
this.adminforth.auth.setAuthCookie({response, username:decoded.userName, pk:decoded.pk})
|
|
120
|
+
return { status: 'ok', allowedLogin: true }
|
|
121
121
|
} else {
|
|
122
122
|
return {error: 'Wrong or expired OTP code'}
|
|
123
123
|
}
|
|
@@ -128,9 +128,9 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
|
|
|
128
128
|
const user = await connector.getRecordByPrimaryKey(this.authResource, decoded.pk)
|
|
129
129
|
const verified = twofactor.verifyToken(user[this.options.twoFaSecretFieldName], body.code);
|
|
130
130
|
if (verified) {
|
|
131
|
-
this.
|
|
132
|
-
this.
|
|
133
|
-
return { status: 'ok',allowedLogin: true }
|
|
131
|
+
this.adminforth.auth.removeCustomCookie({response, name:'totpTemporaryJWT'})
|
|
132
|
+
this.adminforth.auth.setAuthCookie({response, username:decoded.userName, pk:decoded.pk})
|
|
133
|
+
return { status: 'ok', allowedLogin: true }
|
|
134
134
|
} else {
|
|
135
135
|
return {error: 'Wrong or expired OTP code'}
|
|
136
136
|
}
|