XThomasBU commited on
Commit
e84061b
·
verified ·
1 Parent(s): 365c19c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -10,8 +10,8 @@ from chainlit.playground.config import add_llm_provider
10
  from chainlit.playground.providers.langchain import LangchainGenericProvider
11
  import chainlit as cl
12
 
 
13
  import os
14
- from authlib.integrations.requests_client import OAuth2Session # This is a placeholder for whatever OAuth library you're using
15
 
16
  # Retrieving environment variables
17
  OAUTH_CLIENT_ID = os.getenv("OAUTH_CLIENT_ID")
@@ -25,21 +25,16 @@ 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
- redirect_uri=redirect_uri,
29
- scope=OAUTH_SCOPES)
 
30
 
31
- # Redirect the user to the authorization URL
32
- authorization_url, state = oauth_client.authorization_url(OPENID_PROVIDER_URL + '/authorize')
33
 
34
- # Note: The actual redirect and callback handling will depend on your web framework (e.g., Flask, Django)
 
35
 
36
- # After the user authorizes your app and is redirected back to your redirect_uri,
37
- # you would exchange the authorization code for an access token
38
- oauth_client.fetch_token(OPENID_PROVIDER_URL + '/token',
39
- client_secret=OAUTH_CLIENT_SECRET,
40
- authorization_response='URL where user was redirected')
41
-
42
- # Now you can use oauth_client to make authorized requests on behalf of the user
43
 
44
 
45
  # Instantiate the LLM
 
10
  from chainlit.playground.providers.langchain import LangchainGenericProvider
11
  import chainlit as cl
12
 
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")
 
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
+ # The rest of your OAuth flow would go here, including redirecting the user to the authorization_url,
36
+ # and then handling the redirect back to your application to exchange the code for a token.
37
 
 
 
 
 
 
 
 
38
 
39
 
40
  # Instantiate the LLM