1010from piccolo .table import create_db_tables
1111from piccolo .table_reflection import TableStorage
1212from piccolo_admin import create_admin
13+ from piccolo_api .encryption .providers import XChaCha20Provider
14+ from piccolo_api .mfa .authenticator .provider import AuthenticatorProvider
15+ from piccolo_api .mfa .authenticator .tables import (
16+ AuthenticatorSecret as AuthenticatorSecret_ ,
17+ )
1318from piccolo_api .session_auth .tables import SessionsBase
1419
15- DB = SQLiteEngine ("app/admin_user.db" )
20+ DB = SQLiteEngine ()
1621
1722
1823load_dotenv (find_dotenv ())
1924
2025
21- USERNAME = "piccolo"
22- PASSWORD = "piccolo123"
23-
24-
2526class Sessions (SessionsBase , db = DB ):
2627 pass
2728
@@ -30,14 +31,21 @@ class User(BaseUser, tablename="piccolo_user", db=DB):
3031 pass
3132
3233
34+ class AuthenticatorSecret (AuthenticatorSecret_ , db = DB ):
35+ pass
36+
37+
3338async def main ():
3439 # Create auth tables in separate Sqlite DB
35- await create_db_tables (* [User , Sessions ], if_not_exists = True )
40+ await create_db_tables (
41+ * [User , Sessions , AuthenticatorSecret ],
42+ if_not_exists = True ,
43+ )
3644 # Create a admin user in separate Sqlite DB
3745 if not await User .
exists ().
where (
User .
email == "[email protected] " ):
3846 user = User (
39- username = USERNAME ,
40- password = PASSWORD ,
47+ username = os . environ [ " USERNAME" ] ,
48+ password = os . environ [ " PASSWORD" ] ,
41494250 admin = True ,
4351 active = True ,
@@ -72,6 +80,16 @@ async def main():
7280 auth_table = User ,
7381 session_table = Sessions ,
7482 auto_include_related = False ,
83+ mfa_providers = [
84+ AuthenticatorProvider (
85+ encryption_provider = XChaCha20Provider (
86+ encryption_key = os .environb [b"ENCRIPTION_KEY" ]
87+ .decode ("unicode-escape" )
88+ .encode ("latin-1" )
89+ ),
90+ secret_table = AuthenticatorSecret ,
91+ ),
92+ ],
7593 )
7694
7795 # Server
0 commit comments