You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2022/01/27 13:02:29 UTC

[incubator-ponymail-foal] 01/03: Add constant for magic string 'generic'

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit ec41a7411c419c68d98278ed53140ca1e4d7736a
Author: Sebb <se...@apache.org>
AuthorDate: Thu Jan 27 13:00:06 2022 +0000

    Add constant for magic string 'generic'
---
 server/endpoints/oauth.py | 2 +-
 server/plugins/session.py | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/server/endpoints/oauth.py b/server/endpoints/oauth.py
index 8e18e2f..b2f4bd6 100644
--- a/server/endpoints/oauth.py
+++ b/server/endpoints/oauth.py
@@ -57,7 +57,7 @@ async def process(
         if not uid:
             uid = rv.get("email")
         if uid:
-            oauth_provider = rv.get("oauth_domain", "generic")
+            oauth_provider = rv.get("oauth_domain", plugins.session.OAUTH_PROVIDER_DEFAULT)
             cid = hashlib.shake_128(
                 ("%s-%s" % (oauth_provider, uid)).encode("ascii", "ignore")
             ).hexdigest(16)
diff --git a/server/plugins/session.py b/server/plugins/session.py
index 433fd5b..e08cdc0 100644
--- a/server/plugins/session.py
+++ b/server/plugins/session.py
@@ -31,6 +31,7 @@ import copy
 FOAL_MAX_SESSION_AGE = 86400 * 7  # Max 1 week between visits before voiding a session
 FOAL_SAVE_SESSION_INTERVAL = 3600  # Update sessions on disk max once per hour
 DATABASE_NOT_CONNECTED = "Database not connected!"
+OAUTH_PROVIDER_DEFAULT = "generic"
 
 class SessionCredentials:
     uid: str
@@ -46,7 +47,7 @@ class SessionCredentials:
             self.uid = doc.get("uid", "")
             self.name = doc.get("name", "")
             self.email = doc.get("email", "")
-            self.oauth_provider = doc.get("oauth_provider", "generic")
+            self.oauth_provider = doc.get("oauth_provider", OAUTH_PROVIDER_DEFAULT)
             self.authoritative = doc.get("authoritative", False)
             self.admin = doc.get("admin", False)
             self.oauth_data = doc.get("oauth_data", {})
@@ -54,7 +55,7 @@ class SessionCredentials:
             self.uid = ""
             self.name = ""
             self.email = ""
-            self.oauth_provider = "generic"
+            self.oauth_provider = OAUTH_PROVIDER_DEFAULT
             self.authoritative = False
             self.admin = False
             self.oauth_data = {}
@@ -164,7 +165,7 @@ async def get_session(
                     internal.get("oauth_provider")
                     in server.config.oauth.authoritative_domains
                 )
-                creds["oauth_provider"] = internal.get("oauth_provider", "generic")
+                creds["oauth_provider"] = internal.get("oauth_provider", OAUTH_PROVIDER_DEFAULT)
                 creds["oauth_data"] = internal.get("oauth_data", {})
                 # We update admin boolean whenever we fetch session doc, as they may have changed in yaml but not in ES.
                 creds["admin"] = creds["authoritative"] and creds.get('email') in server.config.oauth.admins