1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-06 11:43:51 +00:00

[PM-2014] feat: implement credential creation

This commit is contained in:
Andreas Coroiu
2023-05-08 16:09:46 +02:00
parent 8997fb3422
commit 4e052346bf
4 changed files with 29 additions and 3 deletions

View File

@@ -62,6 +62,16 @@ describe("WebauthnService", () => {
expect(result).toBeUndefined();
});
it("should return credential when navigator.credentials does not throw", async () => {
const credential: Credential = Symbol() as any;
credentials.create.mockResolvedValue(credential);
const options = createNewCredentialOptions();
const result = await webauthnService.createCredential(options);
expect(result).toBe(credential);
});
});
});

View File

@@ -14,12 +14,17 @@ type WebauthnCredentialView = unknown;
@Injectable({ providedIn: CoreAuthModule })
export class WebauthnService {
private credentials: CredentialsContainer;
constructor(
private apiService: WebauthnApiService,
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
@Optional() private credentials: CredentialsContainer = navigator.credentials
) {}
@Optional() credentials: CredentialsContainer
) {
// Default parameters don't work when used with Angular DI
this.credentials = credentials ?? navigator.credentials;
}
async getNewCredentialOptions(
verification: Verification
@@ -43,6 +48,14 @@ export class WebauthnService {
async createCredential(
credentialOptions: NewCredentialOptionsView
): Promise<WebauthnCredentialView | undefined> {
return await new Promise((resolve) => setTimeout(() => resolve(undefined), 1000));
const nativeOptions: CredentialCreationOptions = {
publicKey: credentialOptions.challenge,
};
try {
return await this.credentials.create(nativeOptions);
} catch {
return undefined;
}
}
}

View File

@@ -31,6 +31,8 @@
<h3 bitTypography="h3">{{ "errorCreatingPasskey" | i18n }}</h3>
<p bitTypography="body1">{{ "errorCreatingPasskeyInfo" | i18n }}</p>
</div>
<div *ngIf="currentStep === 'credentialNaming'">Name your credential plz</div>
</ng-container>
<ng-container bitDialogFooter>
<button type="submit" bitButton bitFormButton buttonType="primary">

View File

@@ -76,6 +76,7 @@ export class CreateCredentialDialogComponent {
this.currentStep = "credentialCreationFailed";
return;
}
this.currentStep = "credentialNaming";
}
} finally {
this.dialogRef.disableClose = false;