From 3798a3bd1d894f2d20a84824eccf174c85225667 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Fri, 7 May 2021 16:08:34 +0100 Subject: [PATCH] Add webauthn_credential table This is to store data for registered webauthn credentials, so platform admins can later use them to log in. --- app/models.py | 18 +++++++++ .../versions/0355_add_webauthn_table.py | 37 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 migrations/versions/0355_add_webauthn_table.py diff --git a/app/models.py b/app/models.py index 84b2abdff..7abeaf848 100644 --- a/app/models.py +++ b/app/models.py @@ -2592,3 +2592,21 @@ class ServiceBroadcastProviderRestriction(db.Model): provider = db.Column(db.String, nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) + + +class WebauthnCredential(db.Model): + """ + A table that stores data for registered webauthn credentials. + """ + __tablename__ = "webauthn_credential" + + credential_id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) + aaguid = db.Column(UUID(as_uuid=True), default=uuid.uuid4, nullable=False) + public_key = db.Column(db.String, nullable=False) + + user_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), primary_key=True, nullable=False) + + registration_response = db.Column(JSONB(none_as_null=True), nullable=False, default={}) + + created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) + updated_at = db.Column(db.DateTime, nullable=True, default=datetime.datetime.utcnow) diff --git a/migrations/versions/0355_add_webauthn_table.py b/migrations/versions/0355_add_webauthn_table.py new file mode 100644 index 000000000..6e25ede16 --- /dev/null +++ b/migrations/versions/0355_add_webauthn_table.py @@ -0,0 +1,37 @@ +""" + +Revision ID: 0355_add_webauthn_table +Revises: 0354_government_channel +Create Date: 2021-05-07 17:04:22.017137 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +revision = '0355_add_webauthn_table' +down_revision = '0354_government_channel' + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + 'webauthn_credential', + sa.Column('credential_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('aaguid', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('public_key', sa.String(), nullable=False), + sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('registration_response', postgresql.JSONB(none_as_null=True, astext_type=sa.Text()), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('credential_id', 'user_id') + ) + # ### end Alembic commands ### + + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('webauthn_credential') + # ### end Alembic commands ###