Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: types for signin and signup for webauthn #967

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/ts/recipe/webauthn/api/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 {
Expand Down Expand Up @@ -195,7 +195,7 @@ export default function getAPIImplementation(): APIInterface {
userContext,
}: {
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: RegistrationPayload;
tenantId: string;
session: SessionContainerInterface | undefined;
shouldTryLinkingWithSessionUser: boolean | undefined;
Expand Down Expand Up @@ -364,7 +364,7 @@ export default function getAPIImplementation(): APIInterface {
userContext,
}: {
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: AuthenticationPayload;
tenantId: string;
session?: SessionContainerInterface;
shouldTryLinkingWithSessionUser: boolean | undefined;
Expand Down Expand Up @@ -846,7 +846,7 @@ export default function getAPIImplementation(): APIInterface {
}: {
token: string;
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: RegistrationPayload;
tenantId: string;
options: APIOptions;
userContext: UserContext;
Expand Down
5 changes: 3 additions & 2 deletions lib/ts/recipe/webauthn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
UserVerification,
ResidentKey,
Attestation,
AuthenticationPayload,
} from "./types";
import RecipeUserId from "../../recipeUserId";
import { DEFAULT_TENANT_ID } from "../multitenancy/constants";
Expand Down Expand Up @@ -312,7 +313,7 @@ export default class Wrapper {
}: {
tenantId?: string;
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: AuthenticationPayload;
session?: SessionContainerInterface;
userContext?: Record<string, any>;
}): Promise<
Expand Down Expand Up @@ -345,7 +346,7 @@ export default class Wrapper {
}: {
tenantId?: string;
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: AuthenticationPayload;
userContext?: Record<string, any>;
}): Promise<{ status: "OK" } | { status: "INVALID_CREDENTIALS_ERROR" }> {
const resp = await Recipe.getInstanceOrThrowError().recipeInterfaceImpl.verifyCredentials({
Expand Down
51 changes: 39 additions & 12 deletions lib/ts/recipe/webauthn/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export type RecipeInterface = {

signUp(input: {
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: RegistrationPayload;
session: SessionContainerInterface | undefined;
shouldTryLinkingWithSessionUser: boolean | undefined;
tenantId: string;
Expand Down Expand Up @@ -267,7 +267,7 @@ export type RecipeInterface = {

signIn(input: {
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: AuthenticationPayload;
session: SessionContainerInterface | undefined;
shouldTryLinkingWithSessionUser: boolean | undefined;
tenantId: string;
Expand All @@ -288,7 +288,7 @@ export type RecipeInterface = {

verifyCredentials(input: {
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: AuthenticationPayload;
tenantId: string;
userContext: UserContext;
}): Promise<
Expand All @@ -303,7 +303,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<
Expand Down Expand Up @@ -357,7 +357,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<
Expand Down Expand Up @@ -636,7 +636,7 @@ export type APIInterface = {
| undefined
| ((input: {
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: RegistrationPayload;
tenantId: string;
session: SessionContainerInterface | undefined;
shouldTryLinkingWithSessionUser: boolean | undefined;
Expand Down Expand Up @@ -666,7 +666,7 @@ export type APIInterface = {
| undefined
| ((input: {
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: AuthenticationPayload;
tenantId: string;
session: SessionContainerInterface | undefined;
shouldTryLinkingWithSessionUser: boolean | undefined;
Expand Down Expand Up @@ -711,7 +711,7 @@ export type APIInterface = {
| ((input: {
token: string;
webauthnGeneratedOptionsId: string;
credential: CredentialPayload;
credential: RegistrationPayload;
tenantId: string;
options: APIOptions;
userContext: UserContext;
Expand Down Expand Up @@ -760,16 +760,43 @@ export type TypeWebauthnRecoverAccountEmailDeliveryInput = {

export type TypeWebauthnEmailDeliveryInput = TypeWebauthnRecoverAccountEmailDeliveryInput;

export type CredentialPayload = {
export type CredentialPayloadBase = {
id: string;
rawId: string;
authenticatorAttachment?: "platform" | "cross-platform";
clientExtensionResults: Record<string, unknown>;
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<string, unknown>;
type: "public-key";
};
Loading