diff --git a/lib/ts/recipe/webauthn/api/implementation.ts b/lib/ts/recipe/webauthn/api/implementation.ts index 8a38971a4..e7319b034 100644 --- a/lib/ts/recipe/webauthn/api/implementation.ts +++ b/lib/ts/recipe/webauthn/api/implementation.ts @@ -19,7 +19,7 @@ import { getRecoverAccountLink } from "../utils"; import { logDebugMessage } from "../../../logger"; import { RecipeLevelUser } from "../../accountlinking/types"; import { getUser } from "../../.."; -import { CredentialPayload, ResidentKey, UserVerification } from "../types"; +import { AuthenticationPayload, RegistrationPayload, ResidentKey, UserVerification } from "../types"; export default function getAPIImplementation(): APIInterface { return { @@ -192,7 +192,7 @@ export default function getAPIImplementation(): APIInterface { userContext, }: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationPayload; tenantId: string; session: SessionContainerInterface | undefined; shouldTryLinkingWithSessionUser: boolean | undefined; @@ -361,7 +361,7 @@ export default function getAPIImplementation(): APIInterface { userContext, }: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: AuthenticationPayload; tenantId: string; session?: SessionContainerInterface; shouldTryLinkingWithSessionUser: boolean | undefined; @@ -843,7 +843,7 @@ export default function getAPIImplementation(): APIInterface { }: { token: string; webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationPayload; tenantId: string; options: APIOptions; userContext: UserContext; diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 642cd4a44..75b0abbe8 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -24,6 +24,7 @@ import { UserVerification, ResidentKey, Attestation, + AuthenticationPayload, } from "./types"; import RecipeUserId from "../../recipeUserId"; import { DEFAULT_TENANT_ID } from "../multitenancy/constants"; @@ -308,7 +309,7 @@ export default class Wrapper { }: { tenantId?: string; webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: AuthenticationPayload; session?: SessionContainerInterface; userContext?: Record; }): Promise< @@ -341,7 +342,7 @@ export default class Wrapper { }: { tenantId?: string; webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: AuthenticationPayload; userContext?: Record; }): Promise<{ status: "OK" } | { status: "INVALID_CREDENTIALS_ERROR" }> { const resp = await Recipe.getInstanceOrThrowError().recipeInterfaceImpl.verifyCredentials({ diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index ff9acd4a2..cdf7c6914 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -237,7 +237,7 @@ export type RecipeInterface = { signUp(input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationPayload; session: SessionContainerInterface | undefined; shouldTryLinkingWithSessionUser: boolean | undefined; tenantId: string; @@ -266,7 +266,7 @@ export type RecipeInterface = { signIn(input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: AuthenticationPayload; session: SessionContainerInterface | undefined; shouldTryLinkingWithSessionUser: boolean | undefined; tenantId: string; @@ -287,7 +287,7 @@ export type RecipeInterface = { verifyCredentials(input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: AuthenticationPayload; tenantId: string; userContext: UserContext; }): Promise< @@ -302,7 +302,7 @@ export type RecipeInterface = { // called during operations like creating a user during password reset flow. createNewRecipeUser(input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationPayload; tenantId: string; userContext: UserContext; }): Promise< @@ -356,7 +356,7 @@ export type RecipeInterface = { // (in consumeRecoverAccountToken invalidating the token and in registerOptions for storing the email in the generated options) registerCredential(input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationPayload; userContext: UserContext; recipeUserId: RecipeUserId; }): Promise< @@ -635,7 +635,7 @@ export type APIInterface = { | undefined | ((input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationPayload; tenantId: string; session: SessionContainerInterface | undefined; shouldTryLinkingWithSessionUser: boolean | undefined; @@ -665,7 +665,7 @@ export type APIInterface = { | undefined | ((input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: AuthenticationPayload; tenantId: string; session: SessionContainerInterface | undefined; shouldTryLinkingWithSessionUser: boolean | undefined; @@ -710,7 +710,7 @@ export type APIInterface = { | ((input: { token: string; webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationPayload; tenantId: string; options: APIOptions; userContext: UserContext; @@ -759,16 +759,43 @@ export type TypeWebauthnRecoverAccountEmailDeliveryInput = { export type TypeWebauthnEmailDeliveryInput = TypeWebauthnRecoverAccountEmailDeliveryInput; -export type CredentialPayload = { +export type CredentialPayloadBase = { id: string; rawId: string; + authenticatorAttachment?: "platform" | "cross-platform"; + clientExtensionResults: Record; + type: "public-key"; +}; + +export type AuthenticatorAssertionResponseJSON = { + clientDataJSON: Base64URLString; + authenticatorData: Base64URLString; + signature: Base64URLString; + userHandle?: Base64URLString; +}; + +export type AuthenticatorAttestationResponseJSON = { + clientDataJSON: Base64URLString; + attestationObject: Base64URLString; + authenticatorData?: Base64URLString; + transports?: ("ble" | "cable" | "hybrid" | "internal" | "nfc" | "smart-card" | "usb")[]; + publicKeyAlgorithm?: COSEAlgorithmIdentifier; + publicKey?: Base64URLString; +}; + +export type AuthenticationPayload = CredentialPayloadBase & { + response: AuthenticatorAssertionResponseJSON; +}; + +export type RegistrationPayload = CredentialPayloadBase & { + response: AuthenticatorAttestationResponseJSON; +}; + +export type CredentialPayload = CredentialPayloadBase & { response: { clientDataJSON: string; attestationObject: string; transports?: ("ble" | "cable" | "hybrid" | "internal" | "nfc" | "smart-card" | "usb")[]; userHandle: string; }; - authenticatorAttachment: "platform" | "cross-platform"; - clientExtensionResults: Record; - type: "public-key"; };