Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,28 +13,28 @@ import chainlit as cl
|
|
| 13 |
from authlib.integrations.requests_client import OAuth2Session
|
| 14 |
import os
|
| 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 |
from flask import Flask, request, redirect
|
|
|
|
| 13 |
from authlib.integrations.requests_client import OAuth2Session
|
| 14 |
import os
|
| 15 |
|
| 16 |
+
# Retrieving environment variables
|
| 17 |
+
OAUTH_CLIENT_ID = os.getenv("OAUTH_CLIENT_ID")
|
| 18 |
+
OAUTH_CLIENT_SECRET = os.getenv("OAUTH_CLIENT_SECRET")
|
| 19 |
+
OAUTH_SCOPES = os.getenv("OAUTH_SCOPES").split(',') # Assuming OAUTH_SCOPES is a comma-separated list
|
| 20 |
+
OPENID_PROVIDER_URL = os.getenv("OPENID_PROVIDER_URL")
|
| 21 |
+
SPACE_HOST = os.getenv("SPACE_HOST")
|
| 22 |
+
|
| 23 |
+
# Constructing the redirect URL using the SPACE_HOST variable
|
| 24 |
+
redirect_uri = f"https://{SPACE_HOST}/login/callback"
|
| 25 |
+
|
| 26 |
+
# Initializing the OAuth client/session with the retrieved environment variables
|
| 27 |
+
oauth_client = OAuth2Session(client_id=OAUTH_CLIENT_ID,
|
| 28 |
+
client_secret=OAUTH_CLIENT_SECRET, # Include client_secret if needed for the OAuth2Session setup
|
| 29 |
+
scope=OAUTH_SCOPES,
|
| 30 |
+
redirect_uri=redirect_uri)
|
| 31 |
+
|
| 32 |
+
# Use the corrected method to generate the authorization URL
|
| 33 |
+
authorization_url, state = oauth_client.create_authorization_url(OPENID_PROVIDER_URL + '/authorize')
|
| 34 |
+
|
| 35 |
+
print(authorization_url, state)
|
| 36 |
+
# The rest of your OAuth flow would go here, including redirecting the user to the authorization_url,
|
| 37 |
+
# and then handling the redirect back to your application to exchange the code for a token.
|
| 38 |
|
| 39 |
|
| 40 |
from flask import Flask, request, redirect
|