Browse Source

Refactoring

pull/2498/head
Thomas 2 years ago
parent
commit
c47a3615a5
  1. 26
      apps/api/src/app/auth/web-auth.service.ts
  2. 16
      apps/client/src/app/components/user-account-settings/user-account-settings.component.ts
  3. 2
      apps/client/src/app/components/user-account-settings/user-account-settings.html

26
apps/api/src/app/auth/web-auth.service.ts

@ -88,16 +88,16 @@ export class WebAuthService {
let verification: VerifiedRegistrationResponse; let verification: VerifiedRegistrationResponse;
try { try {
const opts: VerifyRegistrationResponseOpts = { const opts: VerifyRegistrationResponseOpts = {
expectedChallenge,
expectedOrigin: this.expectedOrigin,
expectedRPID: this.rpID,
response: { response: {
clientExtensionResults: credential.clientExtensionResults, clientExtensionResults: credential.clientExtensionResults,
id: credential.id, id: credential.id,
rawId: credential.rawId, rawId: credential.rawId,
response: credential.response, response: credential.response,
type: 'public-key' type: 'public-key'
}, }
expectedChallenge,
expectedOrigin: this.expectedOrigin,
expectedRPID: this.rpID
}; };
verification = await verifyRegistrationResponse(opts); verification = await verifyRegistrationResponse(opts);
} catch (error) { } catch (error) {
@ -123,8 +123,8 @@ export class WebAuthService {
*/ */
existingDevice = await this.deviceService.createAuthDevice({ existingDevice = await this.deviceService.createAuthDevice({
counter, counter,
credentialPublicKey: Buffer.from(credentialPublicKey),
credentialId: Buffer.from(credentialID), credentialId: Buffer.from(credentialID),
credentialPublicKey: Buffer.from(credentialPublicKey),
User: { connect: { id: user.id } } User: { connect: { id: user.id } }
}); });
} }
@ -187,13 +187,6 @@ export class WebAuthService {
let verification: VerifiedAuthenticationResponse; let verification: VerifiedAuthenticationResponse;
try { try {
const opts: VerifyAuthenticationResponseOpts = { const opts: VerifyAuthenticationResponseOpts = {
response: {
clientExtensionResults: credential.clientExtensionResults,
id: credential.id,
rawId: credential.rawId,
response: credential.response,
type: 'public-key'
},
authenticator: { authenticator: {
credentialID: device.credentialId, credentialID: device.credentialId,
credentialPublicKey: device.credentialPublicKey, credentialPublicKey: device.credentialPublicKey,
@ -201,7 +194,14 @@ export class WebAuthService {
}, },
expectedChallenge: `${user.authChallenge}`, expectedChallenge: `${user.authChallenge}`,
expectedOrigin: this.expectedOrigin, expectedOrigin: this.expectedOrigin,
expectedRPID: this.rpID expectedRPID: this.rpID,
response: {
clientExtensionResults: credential.clientExtensionResults,
id: credential.id,
rawId: credential.rawId,
response: credential.response,
type: 'public-key'
}
}; };
verification = await verifyAuthenticationResponse(opts); verification = await verifyAuthenticationResponse(opts);
} catch (error) { } catch (error) {

16
apps/client/src/app/components/user-account-settings/user-account-settings.component.ts

@ -3,10 +3,9 @@ import {
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
OnDestroy, OnDestroy,
OnInit, OnInit
ViewChild
} from '@angular/core'; } from '@angular/core';
import { MatCheckbox, MatCheckboxChange } from '@angular/material/checkbox'; import { MatCheckboxChange } from '@angular/material/checkbox';
import { DataService } from '@ghostfolio/client/services/data.service'; import { DataService } from '@ghostfolio/client/services/data.service';
import { import {
STAY_SIGNED_IN, STAY_SIGNED_IN,
@ -29,14 +28,12 @@ import { catchError, takeUntil } from 'rxjs/operators';
templateUrl: './user-account-settings.html' templateUrl: './user-account-settings.html'
}) })
export class UserAccountSettingsComponent implements OnDestroy, OnInit { export class UserAccountSettingsComponent implements OnDestroy, OnInit {
@ViewChild('toggleSignInWithFingerprintEnabledElement')
signInWithFingerprintElement: MatCheckbox;
public appearancePlaceholder = $localize`Auto`; public appearancePlaceholder = $localize`Auto`;
public baseCurrency: string; public baseCurrency: string;
public currencies: string[] = []; public currencies: string[] = [];
public hasPermissionToUpdateViewMode: boolean; public hasPermissionToUpdateViewMode: boolean;
public hasPermissionToUpdateUserSettings: boolean; public hasPermissionToUpdateUserSettings: boolean;
public isWebAuthnEnabled: boolean;
public language = document.documentElement.lang; public language = document.documentElement.lang;
public locales = [ public locales = [
'de', 'de',
@ -250,9 +247,8 @@ export class UserAccountSettingsComponent implements OnDestroy, OnInit {
} }
private update() { private update() {
if (this.signInWithFingerprintElement) { this.isWebAuthnEnabled = this.webAuthnService.isEnabled() ?? false;
this.signInWithFingerprintElement.checked =
this.webAuthnService.isEnabled() ?? false; this.changeDetectorRef.markForCheck();
}
} }
} }

2
apps/client/src/app/components/user-account-settings/user-account-settings.html

@ -154,8 +154,8 @@
</div> </div>
<div class="pl-1 w-50"> <div class="pl-1 w-50">
<mat-checkbox <mat-checkbox
#toggleSignInWithFingerprintEnabledElement
color="primary" color="primary"
[checked]="isWebAuthnEnabled === true"
[disabled]="!hasPermissionToUpdateUserSettings" [disabled]="!hasPermissionToUpdateUserSettings"
(change)="onSignInWithFingerprintChange($event)" (change)="onSignInWithFingerprintChange($event)"
></mat-checkbox> ></mat-checkbox>

Loading…
Cancel
Save