πŸ”’ Security

Passkey

Passwordless authentication based on FIDO2

πŸ“– Detailed Explanation

Passkey is a password-replacement authentication method based on FIDO2/WebAuthn, and a next-generation authentication standard jointly supported by Apple, Google, and Microsoft. Users can log in to websites using only device authentication such as a fingerprint, face recognition, or PIN. It enables convenient authentication that is resistant to phishing, even without a password.

The core innovation of Passkey is multi-device synchronization. Traditional FIDO2 security keys could only be used on the device they were registered to, but Passkeys are synchronized across multiple devices through iCloud Keychain, Google Password Manager, Windows Hello, and others. You can log in on a new device right away with a Passkey you registered before.

Technically, Passkey uses a private key/public key pair. The private key is stored in the secure area of the user's device (Secure Enclave, TPM) and is never sent to the server. Only the public key is stored on the server, so the private key is not leaked even if the server is hacked. A phishing site cannot use the credential of the original site.

Passkey can be adopted gradually. You can run it alongside existing password login and prioritize it once a user registers a Passkey. With browser autofill (Conditional UI), a Passkey is suggested automatically if one exists, making the user experience very natural.

πŸ’» Code Example

// Passkey 등둝 (Registration)
async function registerPasskey() {
  // μ„œλ²„μ—μ„œ 등둝 μ˜΅μ…˜ κ°€μ Έμ˜€κΈ°
  const optionsRes = await fetch('/api/passkey/register/options', {
    method: 'POST',
    credentials: 'include'
  });
  const options = await optionsRes.json();

  // ArrayBuffer λ³€ν™˜
  options.challenge = base64URLToBuffer(options.challenge);
  options.user.id = base64URLToBuffer(options.user.id);

  // Passkey 생성 (생체인식 ν”„λ‘¬ν”„νŠΈ)
  const credential = await navigator.credentials.create({
    publicKey: {
      ...options,
      authenticatorSelection: {
        residentKey: 'required',        // Passkey (Discoverable Credential)
        userVerification: 'required',   // 생체인식 ν•„μˆ˜
        authenticatorAttachment: 'platform' // λ‚΄μž₯ 인증기 μš°μ„ 
      }
    }
  });

  // μ„œλ²„μ— 등둝
  await fetch('/api/passkey/register/verify', {
    method: 'POST',
    credentials: 'include',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      id: credential.id,
      rawId: bufferToBase64URL(credential.rawId),
      response: {
        clientDataJSON: bufferToBase64URL(credential.response.clientDataJSON),
        attestationObject: bufferToBase64URL(credential.response.attestationObject)
      },
      type: credential.type
    })
  });
}

// Passkey 인증 - Conditional UI (μžλ™μ™„μ„±)
async function authenticateWithConditionalUI() {
  // Conditional UI 지원 확인
  if (!window.PublicKeyCredential?.isConditionalMediationAvailable?.()) {
    return fallbackToTraditionalLogin();
  }

  const optionsRes = await fetch('/api/passkey/authenticate/options');
  const options = await optionsRes.json();
  options.challenge = base64URLToBuffer(options.challenge);

  // mediation: 'conditional'둜 μžλ™μ™„μ„± UI ν™œμ„±ν™”
  // μ‚¬μš©μžκ°€ input ν•„λ“œ 클릭 μ‹œ Passkey μžλ™μ™„μ„± ν‘œμ‹œ
  const credential = await navigator.credentials.get({
    publicKey: options,
    mediation: 'conditional' // 핡심: μžλ™μ™„μ„± 톡합
  });

  // μ„œλ²„ 검증
  const verifyRes = await fetch('/api/passkey/authenticate/verify', {
    method: 'POST',
    credentials: 'include',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      id: credential.id,
      response: {
        clientDataJSON: bufferToBase64URL(credential.response.clientDataJSON),
        authenticatorData: bufferToBase64URL(credential.response.authenticatorData),
        signature: bufferToBase64URL(credential.response.signature),
        userHandle: credential.response.userHandle
          ? bufferToBase64URL(credential.response.userHandle)
          : null
      }
    })
  });

  return verifyRes.json();
}

// HTML: Conditional UI용 input
// <input type="text" autocomplete="username webauthn" />
// autocomplete="webauthn"이 Passkey μžλ™μ™„μ„±μ„ 트리거

// Passkey 지원 μ—¬λΆ€ 확인
async function isPasskeySupported(): Promise<boolean> {
  if (!window.PublicKeyCredential) return false;

  // Platform Authenticator (Touch ID, Windows Hello λ“±) 지원 μ—¬λΆ€
  return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
}

πŸ—£οΈ Examples of Practical Conversations

In product planning:

"Password fatigue is severe and our drop-off rate is high. If we adopt Passkey, users can log in with a single Touch ID and we can also block phishing. It syncs automatically, just like Google and Apple accounts."

In a technical interview:

"What is the difference between Passkey and traditional security keys?" - "Traditional FIDO2 security keys are bound only to that device, but Passkeys are synced via the cloud. They are discoverable credentials, so users can authenticate without entering a user ID."

In UX design:

"How do we make it coexist with the existing password login?" - "Use Conditional UI. If you add autocomplete='webauthn' to the email input, users who have a Passkey get it suggested through autofill, and those who don't go through the existing login flow."

Take a mock interview on this topic β†’ WIA SOOM AI Interview Β· Start for free

⚠️ Cautions

πŸ”— Related Terms

FIDO2 OAuth 2.1 MFA Zero Trust Token-based Auth

πŸ“š Learn More

πŸ“„ passkeys.dev - Passkey Developer Guide πŸ“„ web.dev - Passkey Implementation Guide πŸ“„ Apple Developer - Passkeys