feat: 2FAのバックアップコードの実装 (#121)
This commit is contained in:
@@ -155,6 +155,13 @@ 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,
|
||||
|
@@ -54,8 +54,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
throw new Error('not verified');
|
||||
}
|
||||
|
||||
const backupCodes = Array.from({ length: 20 }, () => {
|
||||
return new OTPAuth.Secret().base32;
|
||||
});
|
||||
|
||||
await this.userProfilesRepository.update(me.id, {
|
||||
twoFactorSecret: profile.twoFactorTempSecret,
|
||||
twoFactorBackupSecret: backupCodes,
|
||||
twoFactorEnabled: true,
|
||||
});
|
||||
|
||||
@@ -64,6 +69,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
detail: true,
|
||||
includeSecrets: true,
|
||||
}));
|
||||
|
||||
return {
|
||||
backupCodes: backupCodes,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -42,6 +42,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
|
||||
await this.userProfilesRepository.update(me.id, {
|
||||
twoFactorSecret: null,
|
||||
twoFactorBackupSecret: null,
|
||||
twoFactorEnabled: false,
|
||||
usePasswordLessLogin: false,
|
||||
});
|
||||
|
Reference in New Issue
Block a user