1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-09 19:28:06 +01:00

[PM-2014] feat: Basic list of credentials

This commit is contained in:
Andreas Coroiu 2023-05-10 09:49:56 +02:00
parent d5ca6fa39f
commit b2a7a29842
No known key found for this signature in database
GPG Key ID: E70B5FFC81DFEC1A
6 changed files with 51 additions and 4 deletions

View File

@ -0,0 +1,14 @@
import { BaseResponse } from "@bitwarden/common/models/response/base.response";
export class WebauthnCredentialResponse extends BaseResponse {
id: string;
name: string;
prf: "active" | "inactive" | "unsupported";
constructor(response: unknown) {
super(response);
this.id = this.getResponseProperty("id");
this.name = this.getResponseProperty("name");
this.prf = this.getResponseProperty("prf");
}
}

View File

@ -2,12 +2,14 @@ import { Injectable } from "@angular/core";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction";
import { ListResponse } from "@bitwarden/common/models/response/list.response";
import { Verification } from "@bitwarden/common/types/verification";
import { CoreAuthModule } from "../../core.module";
import { SaveCredentialRequest } from "./request/save-credential.request";
import { CredentialCreateOptionsResponse } from "./response/credential-create-options.response";
import { WebauthnCredentialResponse } from "./response/webauthn-credential.response";
@Injectable({ providedIn: CoreAuthModule })
export class WebauthnApiService {
@ -28,4 +30,8 @@ export class WebauthnApiService {
await this.apiService.send("POST", "/webauthn", request, true, true);
return true;
}
getCredentials(): Promise<ListResponse<WebauthnCredentialResponse>> {
return this.apiService.send("GET", "/webauthn", null, true, true);
}
}

View File

@ -1,4 +1,5 @@
import { Injectable, Optional } from "@angular/core";
import { from, map, Observable } from "rxjs";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
@ -8,6 +9,7 @@ import { Verification } from "@bitwarden/common/types/verification";
import { CoreAuthModule } from "../../core.module";
import { CredentialCreateOptionsView } from "../../views/credential-create-options.view";
import { WebauthnCredentialView } from "../../views/webauth-credential.view";
import { SaveCredentialRequest } from "./request/save-credential.request";
import { WebauthnAttestationResponseRequest } from "./request/webauthn-attestation-response.request";
@ -86,4 +88,8 @@ export class WebauthnService {
return false;
}
}
getCredentials$(): Observable<WebauthnCredentialView[]> {
return from(this.apiService.getCredentials()).pipe(map((response) => response.data));
}
}

View File

@ -0,0 +1,5 @@
export class WebauthnCredentialView {
id: string;
name: string;
prf: "active" | "inactive" | "unsupported";
}

View File

@ -6,6 +6,10 @@
<a bitLink href="???">{{ "learnMoreAboutPasswordless" | i18n }}</a>
</p>
<ul>
<li *ngFor="let credential of credentials$ | async">{{ credential.name }}</li>
</ul>
<button
type="button"
bitButton

View File

@ -1,8 +1,11 @@
import { Component } from "@angular/core";
import { firstValueFrom } from "rxjs";
import { Component, OnInit } from "@angular/core";
import { firstValueFrom, Observable } from "rxjs";
import { DialogServiceAbstraction } from "@bitwarden/angular/services/dialog";
import { WebauthnService } from "../../core";
import { WebauthnCredentialView } from "../../core/views/webauth-credential.view";
import {
CreateCredentialDialogResult,
openCreateCredentialDialog,
@ -12,8 +15,17 @@ import {
selector: "app-fido2-login-settings",
templateUrl: "fido2-login-settings.component.html",
})
export class Fido2LoginSettingsComponent {
constructor(private dialogService: DialogServiceAbstraction) {}
export class Fido2LoginSettingsComponent implements OnInit {
protected credentials$: Observable<WebauthnCredentialView[]>;
constructor(
private webauthnService: WebauthnService,
private dialogService: DialogServiceAbstraction
) {}
ngOnInit(): void {
this.credentials$ = this.webauthnService.getCredentials$();
}
protected async createCredential() {
const dialogRef = openCreateCredentialDialog(this.dialogService, {});