From 3afb9874142e5722cfc3074bb789872504731a53 Mon Sep 17 00:00:00 2001 From: Hamish Meikle Date: Fri, 1 Mar 2024 12:37:28 +1100 Subject: [PATCH 1/2] Make `authenticatorAttachment` configurable --- src/api/passkey-api-client.ts | 12 ++++++++++-- src/api/types.ts | 2 ++ src/passkey.ts | 7 ++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/api/passkey-api-client.ts b/src/api/passkey-api-client.ts index a4c451a..abadcb8 100644 --- a/src/api/passkey-api-client.ts +++ b/src/api/passkey-api-client.ts @@ -24,11 +24,19 @@ export class PasskeyApiClient { this.baseUrl = baseUrl; } - async registrationOptions({token, userName}: RegistrationOptsRequest): Promise { + async registrationOptions({ + token, + userName, + authenticatorAttachment, + }: RegistrationOptsRequest): Promise { + const body = Boolean(authenticatorAttachment) + ? {username: userName, authenticatorAttachment} + : {username: userName}; + const response = fetch(`${this.baseUrl}/client/user-authenticators/passkey/registration-options`, { method: "POST", headers: this.buildHeaders(token), - body: JSON.stringify({username: userName}), + body: JSON.stringify(body), }); return (await response).json(); diff --git a/src/api/types.ts b/src/api/types.ts index 4b29960..2f293d8 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -1,5 +1,6 @@ import { AuthenticationResponseJSON, + AuthenticatorAttachment, PublicKeyCredentialCreationOptionsJSON, RegistrationResponseJSON, } from "@simplewebauthn/types"; @@ -7,6 +8,7 @@ import { export type RegistrationOptsRequest = { userName?: string; token: string; + authenticatorAttachment?: AuthenticatorAttachment | null; }; export type RegistrationOptsResponse = { diff --git a/src/passkey.ts b/src/passkey.ts index c70d806..155bf5c 100644 --- a/src/passkey.ts +++ b/src/passkey.ts @@ -1,7 +1,7 @@ import {startAuthentication, startRegistration} from "@simplewebauthn/browser"; import {PasskeyApiClient} from "./api"; -import {AuthenticationResponseJSON, RegistrationResponseJSON} from "@simplewebauthn/types"; +import {AuthenticationResponseJSON, RegistrationResponseJSON, AuthenticatorAttachment} from "@simplewebauthn/types"; type PasskeyOptions = { baseUrl: string; @@ -11,6 +11,7 @@ type PasskeyOptions = { type SignUpParams = { userName?: string; token: string; + authenticatorAttachment?: AuthenticatorAttachment | null; }; export class Passkey { @@ -21,8 +22,8 @@ export class Passkey { this.api = new PasskeyApiClient({baseUrl, tenantId}); } - async signUp({userName, token}: SignUpParams) { - const optionsResponse = await this.api.registrationOptions({userName, token}); + async signUp({userName, token, authenticatorAttachment = "platform"}: SignUpParams) { + const optionsResponse = await this.api.registrationOptions({userName, token, authenticatorAttachment}); const registrationResponse = await startRegistration(optionsResponse.options); From e8b3ba5545f6cee1ce7e430b5187c1ffb702f76d Mon Sep 17 00:00:00 2001 From: Hamish Meikle Date: Fri, 1 Mar 2024 12:37:33 +1100 Subject: [PATCH 2/2] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 513201f..cf61547 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@authsignal/browser", - "version": "0.3.7", + "version": "0.4.0", "type": "module", "main": "dist/index.js", "module": "dist/index.js",