summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/SigninApiService.ts
diff options
context:
space:
mode:
authorMar0xy <marie@kaifa.ch>2023-09-26 02:26:30 +0200
committerMar0xy <marie@kaifa.ch>2023-09-26 02:26:30 +0200
commit8595a325ceb24e5a3e2710c2dc78d821f45181bd (patch)
treeafbce0c498dfd3b324dc30c8dfba847d07117c6a /packages/backend/src/server/api/SigninApiService.ts
parentfix: expiredafter time on poll (diff)
parentbuild(deps): bump actions/checkout from 4.0.0 to 4.1.0 (#11900) (diff)
downloadsharkey-8595a325ceb24e5a3e2710c2dc78d821f45181bd.tar.gz
sharkey-8595a325ceb24e5a3e2710c2dc78d821f45181bd.tar.bz2
sharkey-8595a325ceb24e5a3e2710c2dc78d821f45181bd.zip
merge: upstream
Diffstat (limited to 'packages/backend/src/server/api/SigninApiService.ts')
-rw-r--r--packages/backend/src/server/api/SigninApiService.ts28
1 files changed, 9 insertions, 19 deletions
diff --git a/packages/backend/src/server/api/SigninApiService.ts b/packages/backend/src/server/api/SigninApiService.ts
index 977a6eb3f2..ef6411250f 100644
--- a/packages/backend/src/server/api/SigninApiService.ts
+++ b/packages/backend/src/server/api/SigninApiService.ts
@@ -20,6 +20,7 @@ import type { MiLocalUser } from '@/models/User.js';
import { IdService } from '@/core/IdService.js';
import { bindThis } from '@/decorators.js';
import { WebAuthnService } from '@/core/WebAuthnService.js';
+import { UserAuthService } from '@/core/UserAuthService.js';
import { RateLimiterService } from './RateLimiterService.js';
import { SigninService } from './SigninService.js';
import type { AuthenticationResponseJSON } from '@simplewebauthn/typescript-types';
@@ -43,6 +44,7 @@ export class SigninApiService {
private idService: IdService,
private rateLimiterService: RateLimiterService,
private signinService: SigninService,
+ private userAuthService: UserAuthService,
private webAuthnService: WebAuthnService,
) {
}
@@ -125,7 +127,7 @@ export class SigninApiService {
const same = await argon2.verify(profile.password!, password);
const fail = async (status?: number, failure?: { id: string }) => {
- // Append signin history
+ // Append signin history
await this.signinsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
@@ -155,27 +157,15 @@ export class SigninApiService {
});
}
- if (profile.twoFactorBackupSecret?.includes(token)) {
- await this.userProfilesRepository.update({ userId: profile.userId }, {
- twoFactorBackupSecret: profile.twoFactorBackupSecret.filter((secret) => secret !== token),
- });
- return this.signinService.signin(request, reply, user);
- }
-
- const delta = OTPAuth.TOTP.validate({
- secret: OTPAuth.Secret.fromBase32(profile.twoFactorSecret!),
- digits: 6,
- token,
- window: 1,
- });
-
- if (delta === null) {
+ try {
+ await this.userAuthService.twoFactorAuthenticate(profile, token);
+ } catch (e) {
return await fail(403, {
id: 'cdf1235b-ac71-46d4-a3a6-84ccce48df6f',
});
- } else {
- return this.signinService.signin(request, reply, user);
}
+
+ return this.signinService.signin(request, reply, user);
} else if (body.credential) {
if (!same && !profile.usePasswordLessLogin) {
return await fail(403, {
@@ -204,6 +194,6 @@ export class SigninApiService {
reply.code(200);
return authRequest;
}
- // never get here
+ // never get here
}
}