Abhishek Thakur
commited on
Commit
·
c4b5267
1
Parent(s):
1845cc4
random string
Browse files- competitions/oauth.py +4 -1
competitions/oauth.py
CHANGED
@@ -6,6 +6,8 @@ from __future__ import annotations
|
|
6 |
|
7 |
import hashlib
|
8 |
import os
|
|
|
|
|
9 |
import urllib.parse
|
10 |
|
11 |
import fastapi
|
@@ -19,6 +21,7 @@ OAUTH_CLIENT_ID = os.environ.get("OAUTH_CLIENT_ID")
|
|
19 |
OAUTH_CLIENT_SECRET = os.environ.get("OAUTH_CLIENT_SECRET")
|
20 |
OAUTH_SCOPES = os.environ.get("OAUTH_SCOPES")
|
21 |
OPENID_PROVIDER_URL = os.environ.get("OPENID_PROVIDER_URL")
|
|
|
22 |
|
23 |
|
24 |
def attach_oauth(app: fastapi.FastAPI):
|
@@ -29,7 +32,7 @@ def attach_oauth(app: fastapi.FastAPI):
|
|
29 |
# Session Middleware requires a secret key to sign the cookies. Let's use a hash
|
30 |
# of the OAuth secret key to make it unique to the Space + updated in case OAuth
|
31 |
# config gets updated.
|
32 |
-
session_secret =
|
33 |
# ^ if we change the session cookie format in the future, we can bump the version of the session secret to make
|
34 |
# sure cookies are invalidated. Otherwise some users with an old cookie format might get a HTTP 500 error.
|
35 |
app.add_middleware(
|
|
|
6 |
|
7 |
import hashlib
|
8 |
import os
|
9 |
+
import random
|
10 |
+
import string
|
11 |
import urllib.parse
|
12 |
|
13 |
import fastapi
|
|
|
21 |
OAUTH_CLIENT_SECRET = os.environ.get("OAUTH_CLIENT_SECRET")
|
22 |
OAUTH_SCOPES = os.environ.get("OAUTH_SCOPES")
|
23 |
OPENID_PROVIDER_URL = os.environ.get("OPENID_PROVIDER_URL")
|
24 |
+
RANDOM_STRING = "".join(random.choices(string.ascii_letters + string.digits, k=20))
|
25 |
|
26 |
|
27 |
def attach_oauth(app: fastapi.FastAPI):
|
|
|
32 |
# Session Middleware requires a secret key to sign the cookies. Let's use a hash
|
33 |
# of the OAuth secret key to make it unique to the Space + updated in case OAuth
|
34 |
# config gets updated.
|
35 |
+
session_secret = OAUTH_CLIENT_SECRET + RANDOM_STRING
|
36 |
# ^ if we change the session cookie format in the future, we can bump the version of the session secret to make
|
37 |
# sure cookies are invalidated. Otherwise some users with an old cookie format might get a HTTP 500 error.
|
38 |
app.add_middleware(
|