add partial fido2/WebAuthn
This commit is contained in:
		
							parent
							
								
									6c8bb99c61
								
							
						
					
					
						commit
						5401e2594d
					
				
					 14 changed files with 275 additions and 45 deletions
				
			
		
							
								
								
									
										37
									
								
								migrations/versions/52a21983d2a8_add_webauthn.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								migrations/versions/52a21983d2a8_add_webauthn.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
"""add webauthn
 | 
			
		||||
 | 
			
		||||
Revision ID: 52a21983d2a8
 | 
			
		||||
Revises: ff2f2e871dfc
 | 
			
		||||
Create Date: 2022-02-20 17:00:04.531393
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
from alembic import op
 | 
			
		||||
import sqlalchemy as sa
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# revision identifiers, used by Alembic.
 | 
			
		||||
revision = '52a21983d2a8'
 | 
			
		||||
down_revision = 'ff2f2e871dfc'
 | 
			
		||||
branch_labels = None
 | 
			
		||||
depends_on = None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def upgrade():
 | 
			
		||||
    # ### commands auto generated by Alembic - please adjust! ###
 | 
			
		||||
    op.create_table('webauthn_credential',
 | 
			
		||||
    sa.Column('id', sa.Integer(), nullable=False),
 | 
			
		||||
    sa.Column('user_id', sa.Integer(), nullable=False),
 | 
			
		||||
    sa.Column('user_handle', sa.String(length=64), nullable=False),
 | 
			
		||||
    sa.Column('credential_data', sa.LargeBinary(), nullable=False),
 | 
			
		||||
    sa.Column('name', sa.String(length=250), nullable=True),
 | 
			
		||||
    sa.Column('registered', sa.DateTime(), nullable=True),
 | 
			
		||||
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
 | 
			
		||||
    sa.PrimaryKeyConstraint('id')
 | 
			
		||||
    )
 | 
			
		||||
    # ### end Alembic commands ###
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def downgrade():
 | 
			
		||||
    # ### commands auto generated by Alembic - please adjust! ###
 | 
			
		||||
    op.drop_table('webauthn_credential')
 | 
			
		||||
    # ### end Alembic commands ###
 | 
			
		||||
| 
						 | 
				
			
			@ -7,6 +7,9 @@ Create Date: 2022-02-20 16:56:13.258209
 | 
			
		|||
"""
 | 
			
		||||
from alembic import op
 | 
			
		||||
import sqlalchemy as sa
 | 
			
		||||
from sqlalchemy import engine_from_config
 | 
			
		||||
from sqlalchemy.engine import reflection
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# revision identifiers, used by Alembic.
 | 
			
		||||
| 
						 | 
				
			
			@ -18,39 +21,54 @@ depends_on = None
 | 
			
		|||
 | 
			
		||||
def upgrade():
 | 
			
		||||
    # ### commands auto generated by Alembic - please adjust! ###
 | 
			
		||||
    op.create_table('user',
 | 
			
		||||
    sa.Column('id', sa.String(length=36), nullable=False),
 | 
			
		||||
    sa.Column('username', sa.String(), nullable=False),
 | 
			
		||||
    sa.Column('alternative_email', sa.String(), nullable=True),
 | 
			
		||||
    sa.Column('created_at', sa.DateTime(), nullable=False),
 | 
			
		||||
    sa.Column('modified_at', sa.DateTime(), nullable=False),
 | 
			
		||||
    sa.Column('last_login', sa.DateTime(), nullable=True),
 | 
			
		||||
    sa.PrimaryKeyConstraint('id'),
 | 
			
		||||
    sa.UniqueConstraint('username')
 | 
			
		||||
    )
 | 
			
		||||
    op.create_table('user_sign_up',
 | 
			
		||||
    sa.Column('id', sa.Integer(), nullable=False),
 | 
			
		||||
    sa.Column('username', sa.String(), nullable=False),
 | 
			
		||||
    sa.Column('password', sa.String(), nullable=False),
 | 
			
		||||
    sa.Column('alternative_email', sa.String(), nullable=True),
 | 
			
		||||
    sa.Column('created_at', sa.DateTime(), nullable=False),
 | 
			
		||||
    sa.PrimaryKeyConstraint('id')
 | 
			
		||||
    )
 | 
			
		||||
    op.create_table('totp',
 | 
			
		||||
    sa.Column('id', sa.Integer(), nullable=False),
 | 
			
		||||
    sa.Column('secret', sa.String(), nullable=False),
 | 
			
		||||
    sa.Column('name', sa.String(), nullable=False),
 | 
			
		||||
    sa.Column('created_at', sa.DateTime(), nullable=False),
 | 
			
		||||
    sa.Column('user_id', sa.String(length=36), nullable=False),
 | 
			
		||||
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
 | 
			
		||||
    sa.PrimaryKeyConstraint('id')
 | 
			
		||||
 | 
			
		||||
    # init sate, migrate from non versioned db schema
 | 
			
		||||
    # by checking if tables exist
 | 
			
		||||
    
 | 
			
		||||
    config = op.get_context().config
 | 
			
		||||
    engine = engine_from_config(
 | 
			
		||||
        config.get_section(config.config_ini_section), prefix="sqlalchemy."
 | 
			
		||||
    )
 | 
			
		||||
    inspector = reflection.Inspector.from_engine(engine)
 | 
			
		||||
    tables = inspector.get_table_names()
 | 
			
		||||
 | 
			
		||||
    if 'user' not in tables:
 | 
			
		||||
        op.create_table('user',
 | 
			
		||||
        sa.Column('id', sa.String(length=36), nullable=False),
 | 
			
		||||
        sa.Column('username', sa.String(), nullable=False),
 | 
			
		||||
        sa.Column('alternative_email', sa.String(), nullable=True),
 | 
			
		||||
        sa.Column('created_at', sa.DateTime(), nullable=False),
 | 
			
		||||
        sa.Column('modified_at', sa.DateTime(), nullable=False),
 | 
			
		||||
        sa.Column('last_login', sa.DateTime(), nullable=True),
 | 
			
		||||
        sa.PrimaryKeyConstraint('id'),
 | 
			
		||||
        sa.UniqueConstraint('username')
 | 
			
		||||
        )
 | 
			
		||||
    if 'user_sign_up' not in tables:
 | 
			
		||||
        op.create_table('user_sign_up',
 | 
			
		||||
        sa.Column('id', sa.Integer(), nullable=False),
 | 
			
		||||
        sa.Column('username', sa.String(), nullable=False),
 | 
			
		||||
        sa.Column('password', sa.String(), nullable=False),
 | 
			
		||||
        sa.Column('alternative_email', sa.String(), nullable=True),
 | 
			
		||||
        sa.Column('created_at', sa.DateTime(), nullable=False),
 | 
			
		||||
        sa.PrimaryKeyConstraint('id')
 | 
			
		||||
        )
 | 
			
		||||
    if 'totp' not in tables:
 | 
			
		||||
        op.create_table('totp',
 | 
			
		||||
        sa.Column('id', sa.Integer(), nullable=False),
 | 
			
		||||
        sa.Column('secret', sa.String(), nullable=False),
 | 
			
		||||
        sa.Column('name', sa.String(), nullable=False),
 | 
			
		||||
        sa.Column('created_at', sa.DateTime(), nullable=False),
 | 
			
		||||
        sa.Column('user_id', sa.String(length=36), nullable=False),
 | 
			
		||||
        sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
 | 
			
		||||
        sa.PrimaryKeyConstraint('id')
 | 
			
		||||
        )
 | 
			
		||||
    # ### end Alembic commands ###
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def downgrade():
 | 
			
		||||
    pass
 | 
			
		||||
    # ### commands auto generated by Alembic - please adjust! ###
 | 
			
		||||
    op.drop_table('totp')
 | 
			
		||||
    op.drop_table('user_sign_up')
 | 
			
		||||
    op.drop_table('user')
 | 
			
		||||
    #op.drop_table('totp')
 | 
			
		||||
    #op.drop_table('user_sign_up')
 | 
			
		||||
    #op.drop_table('user')
 | 
			
		||||
    # ### end Alembic commands ###
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue