This is a demo project to showcase the use of the Web Authentication API (WebAuthn) with a simulated backend using JavaScript. The demo includes both registration and login flows using the WebAuthn API, and is designed to work without a real server setup by simulating server-side logic within the client-side code.
Web Authentication (WebAuthn) is a web standard for strong authentication, using public key cryptography instead of passwords. This demo project demonstrates the registration and login processes using WebAuthn, with the backend logic simulated in the frontend code.
- Registration: Demonstrates user registration with WebAuthn.
- Login: Demonstrates user login with WebAuthn.
- Simulated Backend: Backend logic is simulated within the client-side JavaScript.
- A modern web browser that supports WebAuthn (e.g., Chrome, Firefox).
-
Clone the repository:
git clone https://github.com/Emmaccen/WebAuth.git cd WebAuth
-
Serve the
index.html
file using a static file server. You can use tools likehttp-server
in Node.js, Python'shttp.server
, or the Live Server extension in VS Code (Recommended).npm install -g http-server http-server .
python -m http.server
- Install the Live Server extension in VS Code.
- Open the project folder in VS Code.
- Right-click on
index.html
and selectOpen with Live Server
.
By default, Live Server runs on port 5500.
If you need to serve an HTTPS URL, you can use port forwarding in VS Code:
- Open the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
). - Search for and select
Forward a Port
. - Enter the port number (default is 5500 for Live Server).
- VS Code will provide an HTTPS URL for accessing your application.
-
Open your browser and navigate to the appropriate URL:
- For
http-server
:http://localhost:8080
(or the appropriate port). - For Python:
http://localhost:8000
. - For Live Server:
http://localhost:5500
or the HTTPS URL provided by VS Code.
- For
WebAuthn requires secure origins (HTTPS) and will not work on insecure origins like http://localhost
or http
.
- Open the
index.html
file in your web browser. - Click the "Register" button to simulate user registration.
- Click the "Login" button to simulate user login.
- The results will be displayed in the output area on the page.
webAuth/
├── index.html # The main HTML file for the demo
└── client.js # The JavaScript file containing client-side and simulated backend logic
└── styles.css # irrelevant for this demo
-
Registration:
- The client requests registration options from the simulated backend.
- The WebAuthn
create
method is called with these options to generate a new credential. - The credential is sent to the simulated backend for registration.
-
Login:
- The client requests authentication options from the simulated backend.
- The WebAuthn
get
method is called with these options to generate an assertion. - The assertion is sent to the simulated backend for verification.
- The backend logic is simulated within the
client.js
file. - Registration options, authentication options, and verification logic are implemented as JavaScript functions.
- This approach allows the demo to run without a real server setup.
Contributions are welcome! If you have any improvements or suggestions, feel free to open an issue or submit a pull request.
- Passwordless login with passkeys
- Web Authentication API
- Create a passkey for passwordless logins
- Sign in with a passkey through form autofill
- Frequently asked questions (FAQ)
This project is licensed under the MIT License. See the LICENSE file for more details.