From 04833ff7e0d2ff85846fae78be9c41c05dc28f38 Mon Sep 17 00:00:00 2001 From: deflax Date: Sat, 6 Apr 2024 15:18:09 +0300 Subject: [PATCH] provide oauth variables --- src/forest/config.py | 29 ++++++++++++++++++++++++++++ src/forest/templates/base.html | 2 +- src/forest/templates/main/index.html | 11 ++++------- variables.env.dist | 3 +++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/forest/config.py b/src/forest/config.py index c22fe1c..f5e922d 100644 --- a/src/forest/config.py +++ b/src/forest/config.py @@ -20,3 +20,32 @@ class Config(object): MAIL_USE_TLS = f"{os.getenv('MAIL_USE_TLS')}" ADMIN_MAIL = f"{os.getenv('ADMIN_MAIL')}" ITEMS_PER_PAGE = f"{os.getenv('ITEMS_PER_PAGE')}" + OAUTH2_PROVIDERS = { + # Google OAuth 2.0 documentation: + # 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', + 'token_url': 'https://accounts.google.com/o/oauth2/token', + 'userinfo': { + 'url': 'https://www.googleapis.com/oauth2/v3/userinfo', + 'email': lambda json: json['email'], + }, + 'scopes': ['https://www.googleapis.com/auth/userinfo.email'], + }, + + # GitHub OAuth 2.0 documentation: + # 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', + 'token_url': 'https://github.com/login/oauth/access_token', + 'userinfo': { + 'url': 'https://api.github.com/user/emails', + 'email': lambda json: json[0]['email'], + }, + 'scopes': ['user:email'], + } + } diff --git a/src/forest/templates/base.html b/src/forest/templates/base.html index 6f05f27..475b064 100644 --- a/src/forest/templates/base.html +++ b/src/forest/templates/base.html @@ -4,7 +4,7 @@ {% import "bootstrap/fixes.html" as fixes %} {% import "bootstrap/utils.html" as util %} -{% block title %}Cloud Builder - Datapoint.bg{% endblock %} +{% block title %}ForestNet{% endblock %} {% block head %} {{ super() }} diff --git a/src/forest/templates/main/index.html b/src/forest/templates/main/index.html index 1ed3d5d..9a75659 100644 --- a/src/forest/templates/main/index.html +++ b/src/forest/templates/main/index.html @@ -39,13 +39,7 @@ - - {% endblock %} @@ -75,6 +69,8 @@



+ +{% if not current_user.is_authenticated %}
@@ -91,6 +87,7 @@

Not registered? Create an account

+{% endif %}
diff --git a/variables.env.dist b/variables.env.dist index b0608b3..3d1a1e5 100644 --- a/variables.env.dist +++ b/variables.env.dist @@ -14,6 +14,9 @@ POSTGRES_DB=forest_prod PGADMIN_DEFAULT_EMAIL=mail@example.com PGADMIN_DEFAULT_PASSWORD=hackme +GOOGLE_CLIENT_ID=changeme +GOOGLE_CLIENT_SECRET=changeme + MAIL_SENDER=mail@example.com MAIL_SUBJECT_PREFIX=ForestNet MAIL_SERVER=smtp.gmail.com