How to store credentials in relational database (postgres / mariadb / mysql) #219
-
As a Software Engineer, I want to persist the created credential into my database, but currently I don't know what I have to persist exactly into the database and how to create the schema. Which columns are important? Is it also possible to prevent users from using the same YubiKey on different accounts, or is the browser smart enough to detect that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
I'll try to consolidate most of this information into a FAQ at some stage as a number of people have been asking.
I also personally store the results from the I have included a rough schema I've used for PostgreSQL below which covers 2 and 3. I personally encrypt the CREATE TABLE IF NOT EXISTS webauthn_credentials (
id SERIAL CONSTRAINT webauthn_credentials_pkey PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_used_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NULL,
rpid VARCHAR(512) NOT NULL,
username VARCHAR(100) NOT NULL,
description VARCHAR(64) NOT NULL,
kid VARCHAR(512) NOT NULL,
aaguid CHAR(36) NULL,
attestation_type VARCHAR(32),
attachment VARCHAR(64) NOT NULL,
transport VARCHAR(64) DEFAULT '',
sign_count INTEGER DEFAULT 0,
clone_warning BOOLEAN NOT NULL DEFAULT FALSE,
discoverable BOOLEAN NOT NULL,
present BOOLEAN NOT NULL DEFAULT FALSE,
verified BOOLEAN NOT NULL DEFAULT FALSE,
backup_eligible BOOLEAN NOT NULL DEFAULT FALSE,
backup_state BOOLEAN NOT NULL DEFAULT FALSE,
public_key BYTEA NOT NULL
);
CREATE UNIQUE INDEX webauthn_credentials_kid_key ON webauthn_credentials (kid);
CREATE UNIQUE INDEX webauthn_credentials_lookup_key ON webauthn_credentials (rpid, username, description);
CREATE TABLE IF NOT EXISTS webauthn_users (
id SERIAL CONSTRAINT webauthn_users_pkey PRIMARY KEY,
rpid VARCHAR(512) NOT NULL,
username VARCHAR(100) NOT NULL,
userid CHAR(64) NOT NULL
);
CREATE UNIQUE INDEX webauthn_users_lookup_key ON webauthn_users (rpid, username); |
Beta Was this translation helpful? Give feedback.
-
I seem to have started using the library before |
Beta Was this translation helpful? Give feedback.
I'll try to consolidate most of this information into a FAQ at some stage as a number of people have been asking.
WebAuthnID
implementation for theUser
interface should always return the same value. Generally speaking this should be an opaque value. This value is what I store in thewebauthn_users
table with theuserid
column. It should be noted there is a conv…