search
HomeTechnology peripheralsIt IndustryDeveloper Guide: How to Implement Passkeys

This guide shows developers how to add passkey-based authentication for better security and user experience. It explains both manual server and client setup, and how Descope simplifies this with a visual interface and pre-built flows.

This tutorial is by Kumar Harsh, a software developer and technical author from India. See more of his work on his website!

Using passkeys improves application security and user convenience. This guide details passkey implementation, from setup to deployment. Following these steps creates a secure and user-friendly authentication experience, reducing unauthorized access and building user trust.

Passkey Authentication: The Basics

Unlike vulnerable passwords, passkeys use public-key cryptography to enhance both security and user experience. Think of a vault: your identity is secured, accessible only with a unique key pair. Passkeys work similarly; each user has a private key (safely stored on their device), and a public key shared with websites.

Login involves the website sending a challenge to the user's device. The private key creates a unique signature (a digital fingerprint), verifying identity without revealing the key itself. This keeps logins secure even if the website is compromised.

Here's a visual representation:

Developer Guide: How to Implement Passkeys

Fig: Passkey authentication ceremony

Implementing Passkeys: The Manual Approach (and why you shouldn't)

While passkeys are innovative, manual implementation is complex and discouraged due to setup difficulty and security risks. It's best to use a supported library.

Generally, manual implementation involves:

  • Server-side setup: This includes key generation, signature verification, attestation handling, and database integration for user information and passkey credentials.
  • Frontend integration: Using JavaScript's navigator.credentials.create() and navigator.credentials.get(), the client guides users through authenticator interactions (fingerprint scans, PINs, etc.) and sends data to the server.

Libraries like SimpleWebAuthn simplify this. It handles key generation, making the process easier than a manual approach.

(A React client and Node.js Express server example project using SimpleWebAuthn is available.)

Server-Side Setup (using SimpleWebAuthn)

The server uses the @simple-webauthn/server package with four key endpoints:

  1. /generate-registration-options: Configures and generates registration options for the client, preventing multiple registrations from the same device. It also generates a challenge.
  2. /verify-registration: Verifies successful on-device registration and saves user details (public key, credential ID, device information) in the database.
  3. /generate-authentication-options: Returns authentication options, retrieving the registered device ID.
  4. /verify-authentication: Verifies successful on-device authentication using a registered device.

This example omits database integration; you'll need to add that for production use.

Client-Side Setup (using SimpleWebAuthn)

The client needs two buttons (for registration and authentication). onRegistrationStart requests configuration from /generate-registration-options, then uses startRegistration() from @simple-webauthn/browser. After successful registration, /verify-registration verifies the result. Authentication follows a similar pattern using /generate-authentication-options, startAuthentication(), and /verify-authentication.

This manual method is complex and requires additional setup and maintenance for user identification and data storage. HTTPS setup requires extra steps.

The Easier Way: Implementing Passkeys with Descope

Descope simplifies passkey implementation, eliminating complex manual setup. It provides a no-code interface for managing authentication flows.

Creating Descope Flows

  1. Sign up for a Descope account.
  2. In the dashboard, create an auth flow. Select Passkeys (WebAuthn) as the primary method.
  3. Optionally, add a 2FA method.
  4. Choose a login screen (potentially with additional registration methods).
  5. Descope generates your auth flow and provides a code snippet with your project ID.

Setting up a React Project

  1. Create a new React project using npm create vite.
  2. Install the Descope SDK: npm install @descope/react-sdk.
  3. Configure the AuthProvider in main.jsx with your project ID.
  4. Use Descope components and hooks in App.js to implement the authentication flow.

This simplified example shows how to integrate Descope's sign-up or sign-in flow:

// Simplified App.js example
import { useDescope, useSession } from '@descope/react-sdk';
import { Descope } from '@descope/react-sdk';

const App = () => {
  const { isAuthenticated, isSessionLoading } = useSession();
  const { logout } = useDescope();

  return (
    <div>
      {!isAuthenticated && (
        <Descope flowId="sign-up-or-in" onSuccess={(e) => console.log(e.detail.user)} onError={(e) => console.log('Error!')} />
      )}
      {isAuthenticated && <button onClick={logout}>Logout</button>}
    </div>
  );
};

Trying Out the App

Run npm run dev and access the app at http://localhost:5173. Register a user, set up passkeys, and test login. You can also enable passkey autofill in the Descope dashboard.

(The complete code is available on GitHub.)

Descope's Drag-and-Drop Authentication

Descope streamlines passkey implementation with a drag-and-drop interface for managing authentication flows. This simplifies setup and modification, making it accessible to developers of all skill levels. It allows for easier, faster, and more accessible logins.

Sign up for a free Descope account to learn more.

The above is the detailed content of Developer Guide: How to Implement Passkeys. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Benefits of Custom Telecommunication SoftwareBenefits of Custom Telecommunication SoftwareMay 11, 2025 am 08:28 AM

Customized telecom software development is undoubtedly a considerable investment. However, in the long run, you may realize that such a project may be more cost-effective because it can increase your productivity like any ready-made solution on the market. Understand the most important advantages of building a customized telecommunications system. Get the exact features you need There are two potential problems with the off-the-shelf telecom software you can buy. Some lack useful features that can significantly improve your productivity. Sometimes you can enhance them with some external integration, but that isn't always enough to make them great. Other software has too many functions and is too complicated to use. You probably won't use some of these (never!). A large number of features usually adds to the price. Based on your needs

CNCF Triggers a Platform Parity Breakthrough for Arm64 and x86CNCF Triggers a Platform Parity Breakthrough for Arm64 and x86May 11, 2025 am 08:27 AM

CI/CD puzzles and solutions for open source software in Arm64 architecture Deploying open source software on Arm64 architecture requires a powerful CI/CD environment. However, there is a difference between the support levels of Arm64 and traditional x86 processor architectures, which are often at a disadvantage. Infrastructure components developers for multiple architectures have certain expectations for their work environment: Consistency: The tools and methods used across platforms are consistent, avoiding the need to change the development process due to the adoption of less popular platforms. Performance: The platform and support mechanism have good performance to ensure that deployment scenarios are not affected by insufficient speed when supporting multiple platforms. Test coverage: Efficiency, compliance and

Top 21 Developer Newsletters to Subscribe To in 2025Top 21 Developer Newsletters to Subscribe To in 2025Apr 24, 2025 am 08:28 AM

Stay informed about the latest tech trends with these top developer newsletters! This curated list offers something for everyone, from AI enthusiasts to seasoned backend and frontend developers. Choose your favorites and save time searching for rel

Serverless Image Processing Pipeline with AWS ECS and LambdaServerless Image Processing Pipeline with AWS ECS and LambdaApr 18, 2025 am 08:28 AM

This tutorial guides you through building a serverless image processing pipeline using AWS services. We'll create a Next.js frontend deployed on an ECS Fargate cluster, interacting with an API Gateway, Lambda functions, S3 buckets, and DynamoDB. Th

CNCF Arm64 Pilot: Impact and InsightsCNCF Arm64 Pilot: Impact and InsightsApr 15, 2025 am 08:27 AM

This pilot program, a collaboration between the CNCF (Cloud Native Computing Foundation), Ampere Computing, Equinix Metal, and Actuated, streamlines arm64 CI/CD for CNCF GitHub projects. The initiative addresses security concerns and performance lim

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor