Skip to content

Commit

Permalink
Use dynamic RP ID
Browse files Browse the repository at this point in the history
  • Loading branch information
lmuntaner committed Dec 12, 2024
1 parent fa5bf21 commit 74c9116
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/frontend/src/utils/multiWebAuthnIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
* then we know which one the user is actually using
* - It doesn't support creating credentials; use `WebAuthnIdentity` for that
*/
import { DOMAIN_COMPATIBILITY } from "$src/featureFlags";
import { PublicKey, Signature, SignIdentity } from "@dfinity/agent";
import { DER_COSE_OID, unwrapDER, WebAuthnIdentity } from "@dfinity/identity";
import { isNullish } from "@dfinity/utils";
import borc from "borc";
import { CredentialData } from "./credential-devices";
import { findWebAuthnRpId, relatedDomains } from "./findWebAuthnRpId";
import { bufferEqual } from "./iiConnection";
import { supportsWebauthRoR } from "./userAgent";

/**
* A SignIdentity that uses `navigator.credentials`. See https://webauthn.guide/ for
Expand Down Expand Up @@ -64,6 +67,14 @@ export class MultiWebAuthnIdentity extends SignIdentity {
return this._actualIdentity.sign(blob);
}

const currentUrl = new URL(window.location.origin);
const userAgent = window.navigator.userAgent;
const rorDomains = relatedDomains();
const rpId =
DOMAIN_COMPATIBILITY.isEnabled() && supportsWebauthRoR(userAgent)
? findWebAuthnRpId(currentUrl.origin, this.credentialData, rorDomains)
: undefined;

const result = (await navigator.credentials.get({
publicKey: {
allowCredentials: this.credentialData.map((cd) => ({
Expand All @@ -72,6 +83,7 @@ export class MultiWebAuthnIdentity extends SignIdentity {
})),
challenge: blob,
userVerification: "discouraged",
rpId,
},
})) as PublicKeyCredential;

Expand Down

0 comments on commit 74c9116

Please sign in to comment.