-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
config.py
77 lines (69 loc) · 3.2 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
from dotenv import load_dotenv
load_dotenv()
basedir = os.path.abspath(os.path.dirname(__file__))
def as_bool(value):
if value:
return value.lower() in ['true', 'yes', 'on', '1']
return False
class Config:
# database options
ALCHEMICAL_DATABASE_URL = os.environ.get('DATABASE_URL') or \
'sqlite:///' + os.path.join(basedir, 'db.sqlite')
ALCHEMICAL_ENGINE_OPTIONS = {'echo': as_bool(os.environ.get('SQL_ECHO'))}
# security options
SECRET_KEY = os.environ.get('SECRET_KEY', 'top-secret!')
DISABLE_AUTH = as_bool(os.environ.get('DISABLE_AUTH'))
ACCESS_TOKEN_MINUTES = int(os.environ.get('ACCESS_TOKEN_MINUTES') or '15')
REFRESH_TOKEN_DAYS = int(os.environ.get('REFRESH_TOKEN_DAYS') or '7')
REFRESH_TOKEN_IN_COOKIE = as_bool(os.environ.get(
'REFRESH_TOKEN_IN_COOKIE') or 'yes')
REFRESH_TOKEN_IN_BODY = as_bool(os.environ.get('REFRESH_TOKEN_IN_BODY'))
RESET_TOKEN_MINUTES = int(os.environ.get('RESET_TOKEN_MINUTES') or '15')
PASSWORD_RESET_URL = os.environ.get('PASSWORD_RESET_URL') or \
'http://localhost:3000/reset'
USE_CORS = as_bool(os.environ.get('USE_CORS') or 'yes')
CORS_SUPPORTS_CREDENTIALS = True
OAUTH2_PROVIDERS = {
# https://developers.google.com/identity/protocols/oauth2/web-server
# #httprest
'google': {
'client_id': os.environ.get('GOOGLE_CLIENT_ID'),
'client_secret': os.environ.get('GOOGLE_CLIENT_SECRET'),
'authorize_url': 'https://accounts.google.com/o/oauth2/auth',
'access_token_url': 'https://accounts.google.com/o/oauth2/token',
'get_user': {
'url': 'https://www.googleapis.com/oauth2/v3/userinfo',
'email': lambda json: json['email'],
},
'scopes': ['https://www.googleapis.com/auth/userinfo.email'],
},
# https://docs.github.com/en/apps/oauth-apps/building-oauth-apps
# /authorizing-oauth-apps
'github': {
'client_id': os.environ.get('GITHUB_CLIENT_ID'),
'client_secret': os.environ.get('GITHUB_CLIENT_SECRET'),
'authorize_url': 'https://github.com/login/oauth/authorize',
'access_token_url': 'https://github.com/login/oauth/access_token',
'get_user': {
'url': 'https://api.github.com/user/emails',
'email': lambda json: json[0]['email'],
},
'scopes': ['user:email'],
},
}
OAUTH2_REDIRECT_URI = os.environ.get('OAUTH2_REDIRECT_URI') or \
'http://localhost:3000/oauth2/{provider}/callback'
# API documentation
APIFAIRY_TITLE = 'Microblog API'
APIFAIRY_VERSION = '1.0'
APIFAIRY_UI = os.environ.get('DOCS_UI', 'elements')
APIFAIRY_TAGS = ['tokens', 'users', 'posts']
# email options
MAIL_SERVER = os.environ.get('MAIL_SERVER', 'localhost')
MAIL_PORT = int(os.environ.get('MAIL_PORT') or '25')
MAIL_USE_TLS = as_bool(os.environ.get('MAIL_USE_TLS'))
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
MAIL_DEFAULT_SENDER=os.environ.get('MAIL_DEFAULT_SENDER',