Spaces:
Paused
Paused
update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import spaces
|
|
| 9 |
TENANT_ID = '2b093ced-2571-463f-bc3e-b4f8bcb427ee'
|
| 10 |
CLIENT_ID = '2a7c884c-942d-49e2-9e5d-7a29d8a0d3e5'
|
| 11 |
CLIENT_SECRET = 'EOF8Q~kKHCRgx8tnlLM-H8e93ifetxI6x7sU6bGW'
|
| 12 |
-
REDIRECT_URI = 'https://sanjeevbora-chatbot.hf.space/'
|
| 13 |
AUTH_URL = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/authorize"
|
| 14 |
TOKEN_URL = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token"
|
| 15 |
SCOPE = 'User.Read'
|
|
@@ -20,9 +20,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|
| 20 |
global access_token
|
| 21 |
if self.path.startswith("/callback"):
|
| 22 |
# Capture the authorization code
|
| 23 |
-
code = self.path.split("code=")[1]
|
| 24 |
-
print("Authorization code received:", code)
|
| 25 |
-
|
| 26 |
response = requests.post(TOKEN_URL, data={
|
| 27 |
'client_id': CLIENT_ID,
|
| 28 |
'client_secret': CLIENT_SECRET,
|
|
@@ -31,8 +29,6 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|
| 31 |
'redirect_uri': REDIRECT_URI
|
| 32 |
})
|
| 33 |
token_data = response.json()
|
| 34 |
-
print("Token response:", response.json())
|
| 35 |
-
print("Token data:", token_data)
|
| 36 |
access_token = token_data.get('access_token')
|
| 37 |
self.send_response(200)
|
| 38 |
self.end_headers()
|
|
@@ -54,16 +50,16 @@ def login():
|
|
| 54 |
def check_login():
|
| 55 |
return "You are logged in!" if access_token else "You are not logged in."
|
| 56 |
|
| 57 |
-
@spaces.GPU(duration=60)
|
| 58 |
def handle_login_click():
|
| 59 |
login()
|
| 60 |
-
return
|
| 61 |
|
|
|
|
| 62 |
def gradio_interface():
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
gr.Markdown("### Welcome to the App")
|
| 65 |
btn_login = gr.Button("Login with Microsoft")
|
| 66 |
-
output = gr.Textbox(label="Status")
|
| 67 |
|
| 68 |
btn_login.click(handle_login_click, None, output)
|
| 69 |
|
|
|
|
| 9 |
TENANT_ID = '2b093ced-2571-463f-bc3e-b4f8bcb427ee'
|
| 10 |
CLIENT_ID = '2a7c884c-942d-49e2-9e5d-7a29d8a0d3e5'
|
| 11 |
CLIENT_SECRET = 'EOF8Q~kKHCRgx8tnlLM-H8e93ifetxI6x7sU6bGW'
|
| 12 |
+
REDIRECT_URI = 'https://sanjeevbora-chatbot.hf.space/callback' # Ensure this matches your app registration
|
| 13 |
AUTH_URL = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/authorize"
|
| 14 |
TOKEN_URL = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token"
|
| 15 |
SCOPE = 'User.Read'
|
|
|
|
| 20 |
global access_token
|
| 21 |
if self.path.startswith("/callback"):
|
| 22 |
# Capture the authorization code
|
| 23 |
+
code = self.path.split("code=")[1].split("&")[0] # Ensure you get just the code
|
|
|
|
|
|
|
| 24 |
response = requests.post(TOKEN_URL, data={
|
| 25 |
'client_id': CLIENT_ID,
|
| 26 |
'client_secret': CLIENT_SECRET,
|
|
|
|
| 29 |
'redirect_uri': REDIRECT_URI
|
| 30 |
})
|
| 31 |
token_data = response.json()
|
|
|
|
|
|
|
| 32 |
access_token = token_data.get('access_token')
|
| 33 |
self.send_response(200)
|
| 34 |
self.end_headers()
|
|
|
|
| 50 |
def check_login():
|
| 51 |
return "You are logged in!" if access_token else "You are not logged in."
|
| 52 |
|
|
|
|
| 53 |
def handle_login_click():
|
| 54 |
login()
|
| 55 |
+
return "Please complete the login process in the opened window."
|
| 56 |
|
| 57 |
+
@spaces.GPU(duration=60)
|
| 58 |
def gradio_interface():
|
| 59 |
with gr.Blocks() as demo:
|
| 60 |
gr.Markdown("### Welcome to the App")
|
| 61 |
btn_login = gr.Button("Login with Microsoft")
|
| 62 |
+
output = gr.Textbox(label="Status", interactive=False)
|
| 63 |
|
| 64 |
btn_login.click(handle_login_click, None, output)
|
| 65 |
|