Skip to content

Commit de2d7b0

Browse files
authored
Merge pull request #1 from sinisaos/mfa_providers
add `mfa_providers` to template
2 parents 1306516 + 2a10c35 commit de2d7b0

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 sinisaos
3+
Copyright (c) 2024 piccolo-orm
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Experimenting with using a dockerized Piccolo Admin with an existing (legacy) da
55
Clone repository.
66

77
```bash
8-
git clone https://github.com/sinisaos/piccolo-admin-docker.git
8+
git clone https://github.com/piccolo-orm/piccolo-admin-docker.git
99
```
1010

1111
Creating an `.env` file.
@@ -21,7 +21,7 @@ Creating a Docker image.
2121
docker build -t piccolo_admin .
2222
```
2323

24-
Running a Docker image (using the `--network=host` flag because I'm using an existing database from the local machine).
24+
Running a Docker image (use the `--network=host` flag for an existing database from the local machine).
2525

2626
```bash
2727
docker run -d --network=host --name admin_container piccolo_admin

app/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ DB_USER="your_db_user"
33
DB_PASSWORD="your_db_password"
44
DB_HOST="your_host"
55
DB_PORT=5432
6+
USERNAME="piccolo"
7+
PASSWORD="piccolo123"
8+
9+
ENCRIPTION_KEY="\xb7(\xa5\xa6\xa4&\xeb\x8eI\xfe_Y\x16\x12\xf4\xf4\xa8|\xc6#\xd1\x02\xa2s\x03]\xea\x12\xb9\xf1\xa2\xb3"

app/admin_user.db

-20 KB
Binary file not shown.

app/main.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
from piccolo.table import create_db_tables
1111
from piccolo.table_reflection import TableStorage
1212
from 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+
)
1318
from piccolo_api.session_auth.tables import SessionsBase
1419

15-
DB = SQLiteEngine("app/admin_user.db")
20+
DB = SQLiteEngine()
1621

1722

1823
load_dotenv(find_dotenv())
1924

2025

21-
USERNAME = "piccolo"
22-
PASSWORD = "piccolo123"
23-
24-
2526
class Sessions(SessionsBase, db=DB):
2627
pass
2728

@@ -30,15 +31,22 @@ class User(BaseUser, tablename="piccolo_user", db=DB):
3031
pass
3132

3233

34+
class AuthenticatorSecret(AuthenticatorSecret_, db=DB):
35+
pass
36+
37+
3338
async 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
37-
if not await User.exists().where(User.email == "[email protected]"):
45+
if not await User.exists().where(User.email == os.environ["EMAIL"]):
3846
user = User(
39-
username=USERNAME,
40-
password=PASSWORD,
41-
47+
username=os.environ["USERNAME"],
48+
password=os.environ["PASSWORD"],
49+
email=os.environ["EMAIL"],
4250
admin=True,
4351
active=True,
4452
superuser=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

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
https://github.com/piccolo-orm/piccolo/archive/master.zip
2-
piccolo-admin
31
asyncpg
42
aiosqlite
53
hypercorn
4+
piccolo
5+
piccolo-admin
6+
piccolo_api[authenticator,pynacl]
67
python-dotenv

0 commit comments

Comments
 (0)