This repository contains a Golang implementation of a WebAuthn server. It provides functionality for user registration and authentication using the WebAuthn protocol.
- User registration with WebAuthn credentials
- User authentication using WebAuthn
- Session management for WebAuthn operations
- Pluggable storage for user credentials (currently using in-memory storage)
- Go 1.22 or higher
- Required dependencies (see
go.mod
file)
-
Clone the repository:
git clone https://github.com/amosel/webauthn-demo.git
-
Install the dependencies:
go mod download
-
Generate TLS certificates:
openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt
-
Run the server:
go run .
-
Access the server at
https://localhost:443
in your web browser.
main.go
: Entry point of the server applicationmodels.go
: Defines the data models used in the applicationutils.go
: Contains utility functionswebauthn_handlers.go
: Implements the HTTP handlers for WebAuthn operationswebauthn_store.go
: Provides the storage interface and implementation for WebAuthn sessionswebauthn_user.go
: Defines the WebAuthn user interface and related functionsstatic/
: Directory containing static files (e.g., HTML, CSS, JavaScript)
- Initializes the WebAuthn session store
- Sets up router and handlers for WebAuthn operations
- Starts the HTTPS server
- Defines
User
,WebAuthnConfiguration
,WebAuthn
, andSessionRequest
structs
- Implements
isValidEmail
function to validate email addresses
- Defines handlers for beginning and finishing WebAuthn registration and login
- Includes functions to add credentials to users
- Manages in-progress WebAuthn registrations and logins
- Implements functions to begin and finish WebAuthn registration and login
- Implements the
WebAuthnUser
struct and required methods for WebAuthn user interface - Includes functions to load WebAuthn credentials and create
WebAuthnUser
fromUser
- Provides a simple front-end interface for testing WebAuthn registration and login
- Includes JavaScript functions to handle WebAuthn registration and login processes
- Implement persistent storage for user credentials (e.g., database)
- Add support for additional WebAuthn options and configurations
- Enhance error handling and logging
- Implement user management functionality
- Add unit tests and integration tests
- Improve documentation and code comments
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License.