fix: name passed in sync authorize (#2665)

# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):

---------

Co-authored-by: Stan Girard <stan@quivr.app>
This commit is contained in:
Stan Girard 2024-06-12 14:20:10 +02:00 committed by GitHub
parent e2f7ad1a45
commit 6bd1a5b334
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View File

@ -2,15 +2,15 @@ import os
import requests
from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.responses import HTMLResponse
from logger import get_logger
from middlewares.auth import AuthBearer, get_current_user
from modules.sync.dto.inputs import SyncsUserInput, SyncUserUpdateInput
from modules.sync.service.sync_service import SyncService, SyncUserService
from modules.user.entity.user_identity import UserIdentity
from msal import PublicClientApplication
from .successfull_connection import successfullConnectionPage
from fastapi.responses import HTMLResponse
from .successfull_connection import successfullConnectionPage
# Initialize logger
logger = get_logger(__name__)
@ -54,7 +54,7 @@ def authorize_azure(
"""
client = PublicClientApplication(CLIENT_ID, authority=AUTHORITY)
logger.debug(f"Authorizing Azure sync for user: {current_user.id}")
state = f"user_id={current_user.id}"
state = f"user_id={current_user.id}, name={name}"
authorization_url = client.get_authorization_request_url(
scopes=SCOPE, redirect_uri=REDIRECT_URI, state=state
)
@ -83,8 +83,10 @@ def oauth2callback_azure(request: Request):
"""
client = PublicClientApplication(CLIENT_ID, authority=AUTHORITY)
state = request.query_params.get("state")
state_split = state.split(",")
current_user = state_split[0].split("=")[1] # Extract user_id from state
name = state_split[1].split("=")[1] if state else None
state_dict = {"state": state}
current_user = state.split("=")[1] # Extract user_id from state
logger.debug(
f"Handling OAuth2 callback for user: {current_user} with state: {state}"
)

View File

@ -80,7 +80,7 @@ def authorize_google(
scopes=SCOPES,
redirect_uri=redirect_uri,
)
state = f"user_id={current_user.id}"
state = f"user_id={current_user.id}, name={name}"
authorization_url, state = flow.authorization_url(
access_type="offline",
include_granted_scopes="true",
@ -115,7 +115,9 @@ def oauth2callback_google(request: Request):
state = request.query_params.get("state")
state_dict = {"state": state}
logger.info(f"State: {state}")
current_user = state.split("=")[1] if state else None
state_split = state.split(",")
current_user = state_split[0].split("=")[1] if state else None
name = state_split[1].split("=")[1] if state else None
logger.debug(
f"Handling OAuth2 callback for user: {current_user} with state: {state}"
)