Skip to content
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Updated FDI support to 4.2
- Added `recipeUserId` in the WebAuthn list credentials response
- Fix WebAuthn credential listing and removal to work even when the WebAuthn user is not the primary user and when there are multiple WebAuthn users linked
- Prevent removal of WebAuthn credentials unless all session claims are satisfied
- Change how sessions are fetched before listing, removing and adding WebAuthn credentials

Expand Down Expand Up @@ -987,7 +988,7 @@ Session.init({
input.userId,
input.recipeUserId,
input.tenantId,
input.userContext,
input.userContext
)),
};

Expand Down Expand Up @@ -1015,7 +1016,7 @@ Session.init({
input.recipeUserId,
input.tenantId,
input.accessTokenPayload,
input.userContext,
input.userContext
)),
};

Expand Down
54 changes: 48 additions & 6 deletions lib/build/recipe/webauthn/api/implementation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 47 additions & 6 deletions lib/ts/recipe/webauthn/api/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,14 +986,36 @@ export default function getAPIImplementation(): APIInterface {
},

listCredentialsGET: async function ({ options, userContext, session }) {
const credentials = await options.recipeImplementation.listCredentials({
recipeUserId: session.getRecipeUserId().getAsString(),
userContext,
});
const existingUser = await getUser(session.getUserId(), userContext);
if (!existingUser) {
return {
status: "GENERAL_ERROR",
message: "User not found",
};
}

const recipeUserIds = existingUser.loginMethods
.filter((lm) => lm.recipeId === "webauthn")
?.map((lm) => lm.recipeUserId);

const credentials: {
webauthnCredentialId: string;
relyingPartyId: string;
createdAt: number;
recipeUserId: string;
}[] = [];
for (const recipeUserId of recipeUserIds) {
const listCredentialsResponse = await options.recipeImplementation.listCredentials({
recipeUserId: recipeUserId.getAsString(),
userContext,
});

credentials.push(...listCredentialsResponse.credentials);
}

return {
status: "OK",
credentials: credentials.credentials.map((credential) => ({
credentials: credentials.map((credential) => ({
recipeUserId: credential.recipeUserId,
webauthnCredentialId: credential.webauthnCredentialId,
relyingPartyId: credential.relyingPartyId,
Expand Down Expand Up @@ -1076,9 +1098,28 @@ export default function getAPIImplementation(): APIInterface {
]);
}

const user = await getUser(session.getUserId(), userContext);
if (!user) {
return {
status: "GENERAL_ERROR",
message: "User not found",
};
}

const recipeUserId = user.loginMethods.find(
(lm) => lm.recipeId === "webauthn" && lm.webauthn?.credentialIds.includes(webauthnCredentialId)
)?.recipeUserId;

if (!recipeUserId) {
return {
status: "GENERAL_ERROR",
message: "User not found",
};
}

const removeCredentialResponse = await options.recipeImplementation.removeCredential({
webauthnCredentialId,
recipeUserId: session.getRecipeUserId().getAsString(),
recipeUserId: recipeUserId.getAsString(),
userContext,
});
if (removeCredentialResponse.status !== "OK") {
Expand Down
Loading