[core] Add fix secret as config option

This commit is contained in:
Cathy Hu 2020-09-12 00:01:30 +02:00
parent 7b8d17b77b
commit b46c605623
2 changed files with 4 additions and 2 deletions

View file

@ -18,6 +18,8 @@ Example:
""" """
from argparse import ArgumentParser from argparse import ArgumentParser
from nacl.secret import SecretBox
from nacl.utils import random
from pytoml import load from pytoml import load
from sys import argv from sys import argv
@ -25,6 +27,7 @@ from sys import argv
config = { config = {
'database_connection': 'sqlite:////tmp/kibicara.sqlite', 'database_connection': 'sqlite:////tmp/kibicara.sqlite',
'frontend_url': 'http://127.0.0.1:4200', # url of frontend, change in prod 'frontend_url': 'http://127.0.0.1:4200', # url of frontend, change in prod
'secret': random(SecretBox.KEY_SIZE).hex(), # generate with: openssl rand -hex 32
# production params # production params
'frontend_path': None, # required, path to frontend html/css/js files 'frontend_path': None, # required, path to frontend html/css/js files
'production': True, 'production': True,

View file

@ -15,7 +15,6 @@ from logging import getLogger
from nacl.encoding import URLSafeBase64Encoder from nacl.encoding import URLSafeBase64Encoder
from nacl.exceptions import CryptoError from nacl.exceptions import CryptoError
from nacl.secret import SecretBox from nacl.secret import SecretBox
from nacl.utils import random
from passlib.hash import argon2 from passlib.hash import argon2
from ormantic.exceptions import NoMatch from ormantic.exceptions import NoMatch
from pickle import dumps, loads from pickle import dumps, loads
@ -38,7 +37,7 @@ class BodyAccessToken(BaseModel):
oauth2_scheme = OAuth2PasswordBearer(tokenUrl='/api/admin/login') oauth2_scheme = OAuth2PasswordBearer(tokenUrl='/api/admin/login')
secret_box = SecretBox(random(SecretBox.KEY_SIZE)) secret_box = SecretBox(bytes.fromhex(config['secret']))
def to_token(**kwargs): def to_token(**kwargs):