Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 40 additions & 29 deletions backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,19 @@ def _get_auth_response(access_token: str, redirect_to_callback: bool) -> Respons
return JSONResponse(response_dict)


def _get_oauth_redirect_error(request: Request, error: str) -> Response:
def _get_oauth_redirect_error(
request: Request, error: str, status_code: int = 302
) -> Response:
"""Get the redirect response for an OAuth error."""
params = urllib.parse.urlencode(
{
"error": error,
}
)
response = RedirectResponse(url=str(request.url_for("login")) + "?" + params)
response = RedirectResponse(
url=str(request.url_for("login")) + "?" + params,
status_code=status_code,
)
return response


Expand Down Expand Up @@ -665,32 +670,33 @@ async def oauth_callback(
)

if error:
return _get_oauth_redirect_error(request, error)
logger.warning("OAuth provider %s returned error: %s", provider_id, error)
return _get_oauth_redirect_error(request, "oauthSignin")

if not code or not state:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Missing code or state",
)
return _get_oauth_redirect_error(request, "oauthSignin")
Comment thread
dokterbob marked this conversation as resolved.

try:
validate_oauth_state_cookie(request, state)
except Exception as e:
logger.exception("Unable to validate oauth state: %s", e)

raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Unauthorized",
)
return _get_oauth_redirect_error(request, "oauthSignin")
Comment thread
dokterbob marked this conversation as resolved.

url = get_user_facing_url(request.url)
token = await provider.get_token(code, url)

(raw_user_data, default_user) = await provider.get_user_info(token)
try:
token = await provider.get_token(code, url)
(raw_user_data, default_user) = await provider.get_user_info(token)
user = await config.code.oauth_callback(
provider_id, token, raw_user_data, default_user
)
except asyncio.CancelledError:
raise
except Exception as e:
logger.exception("OAuth callback error: %s", e)
return _get_oauth_redirect_error(request, "oauthSignin")
Comment thread
Copilot marked this conversation as resolved.

user = await config.code.oauth_callback(
provider_id, token, raw_user_data, default_user
)
if not user:
return _get_oauth_redirect_error(request, "oauthSignin")

response = await _authenticate_user(request, user, redirect_to_callback=True)

Expand Down Expand Up @@ -724,22 +730,27 @@ async def oauth_azure_hf_callback(
)

if error:
return _get_oauth_redirect_error(request, error)
logger.warning("OAuth provider %s returned error: %s", provider_id, error)
return _get_oauth_redirect_error(request, "oauthSignin", status_code=303)

if not code:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Missing code",
)
return _get_oauth_redirect_error(request, "oauthSignin", status_code=303)

url = get_user_facing_url(request.url)
token = await provider.get_token(code, url)

(raw_user_data, default_user) = await provider.get_user_info(token)
try:
token = await provider.get_token(code, url)
(raw_user_data, default_user) = await provider.get_user_info(token)
user = await config.code.oauth_callback(
provider_id, token, raw_user_data, default_user, id_token
)
except asyncio.CancelledError:
raise
except Exception as e:
logger.exception("OAuth callback error: %s", e)
return _get_oauth_redirect_error(request, "oauthSignin", status_code=303)

user = await config.code.oauth_callback(
provider_id, token, raw_user_data, default_user, id_token
)
if not user:
return _get_oauth_redirect_error(request, "oauthSignin", status_code=303)

response = await _authenticate_user(request, user, redirect_to_callback=True)

Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/ar-SA.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "تعذر تسجيل الدخول",
"signin": "حاول تسجيل الدخول بحساب آخر",
"oauthSignin": "حاول تسجيل الدخول بحساب آخر",
"oauthSignin": "فشل تسجيل الدخول. يرجى المحاولة مرة أخرى، أو استخدام طريقة تسجيل دخول مختلفة.",
"redirectUriMismatch": "عنوان URI لإعادة التوجيه لا يتطابق مع تكوين تطبيق OAuth",
"oauthCallback": "حاول تسجيل الدخول بحساب آخر",
"oauthCreateAccount": "حاول تسجيل الدخول بحساب آخر",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "সাইন ইন করা সম্ভব হচ্ছে না",
"signin": "অন্য একটি অ্যাকাউন্ট দিয়ে সাইন ইন করার চেষ্টা করুন",
"oauthSignin": "অন্য একটি অ্যাকাউন্ট দিয়ে সাইন ইন করার চেষ্টা করুন",
"oauthSignin": "সাইন ইন ব্যর্থ হয়েছে। আবার চেষ্টা করুন, অথবা অন্য একটি সাইন ইন পদ্ধতি ব্যবহার করুন",
"redirectUriMismatch": "রিডাইরেক্ট URI ওআথ অ্যাপ কনফিগারেশনের সাথে মিলছে না",
"oauthCallback": "অন্য একটি অ্যাকাউন্ট দিয়ে সাইন ইন করার চেষ্টা করুন",
"oauthCreateAccount": "অন্য একটি অ্যাকাউন্ট দিয়ে সাইন ইন করার চেষ্টা করুন",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/da-DK.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "Kunne ikke logge ind",
"signin": "Prøv at logge ind med en anden konto",
"oauthSignin": "Prøv at logge ind med en anden konto",
"oauthSignin": "Log ind mislykkedes. Prøv igen, eller brug en anden loginmetode.",
"redirectUriMismatch": "Omdirigerings-URI'en matcher ikke oauth-app konfigurationen",
"oauthCallback": "Prøv at logge ind med en anden konto",
"oauthCreateAccount": "Prøv at logge ind med en anden konto",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "Anmeldung fehlgeschlagen",
"signin": "Versuche dich mit einem anderen Konto anzumelden",
"oauthSignin": "Versuche dich mit einem anderen Konto anzumelden",
"oauthSignin": "Anmeldung fehlgeschlagen. Bitte versuche es erneut oder verwende eine andere Anmeldemethode.",
"redirectUriMismatch": "Der Redirect-URI stimmt nicht mit der Konfiguration der Oauth-Anwendung überein",
"oauthCallback": "Versuche dich mit einem anderen Konto anzumelden",
"oauthCreateAccount": "Versuche dich mit einem anderen Konto anzumelden",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/el-GR.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "Δεν είναι δυνατή η σύνδεση",
"signin": "Δοκιμάστε να συνδεθείτε με διαφορετικό λογαριασμό",
"oauthSignin": "Δοκιμάστε να συνδεθείτε με διαφορετικό λογαριασμό",
"oauthSignin": "Η σύνδεση απέτυχε. Παρακαλώ δοκιμάστε ξανά ή χρησιμοποιήστε διαφορετική μέθοδο σύνδεσης.",
"redirectUriMismatch": "Ο σύνδεσμος ανακατεύθυνσης δεν ταιριάζει με τη ρύθμιση της αυθεντικοποιήσης της εφαρμογής",
"oauthCallback": "Δοκιμάστε να συνδεθείτε με διαφορετικό λογαριασμό",
"oauthCreateAccount": "Δοκιμάστε να συνδεθείτε με διαφορετικό λογαριασμό",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "Unable to sign in",
"signin": "Try signing in with a different account",
"oauthSignin": "Try signing in with a different account",
"oauthSignin": "Sign in failed. Please try again, or use a different sign-in method.",
"redirectUriMismatch": "The redirect URI is not matching the oauth app configuration",
"oauthCallback": "Try signing in with a different account",
"oauthCreateAccount": "Try signing in with a different account",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "No se pudo iniciar sesión",
"signin": "Intenta iniciar sesión con otra cuenta",
"oauthSignin": "Intenta iniciar sesión con otra cuenta",
"oauthSignin": "Error al iniciar sesión. Por favor, inténtalo de nuevo o usa un método de inicio de sesión diferente.",
"redirectUriMismatch": "El URI de redirección no coincide con la configuración de la aplicación OAuth",
"oauthCallback": "Intenta iniciar sesión con otra cuenta",
"oauthCreateAccount": "Intenta iniciar sesión con otra cuenta",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "Impossible de se connecter",
"signin": "Essayez de vous connecter avec un autre compte",
"oauthSignin": "Essayez de vous connecter avec un autre compte",
"oauthSignin": "La connexion a échoué. Veuillez réessayer ou utiliser un autre mode de connexion.",
"redirectUriMismatch": "L'URI de redirection ne correspond pas à la configuration de l'application oauth",
"oauthCallback": "Essayez de vous connecter avec un autre compte",
"oauthCreateAccount": "Essayez de vous connecter avec un autre compte",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/gu.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "સાઇન ઇન કરી શકાયું નથી",
"signin": "અલગ એકાઉન્ટથી સાઇન ઇન કરવાનો પ્રયાસ કરો",
"oauthSignin": "અલગ એકાઉન્ટથી સાઇન ઇન કરવાનો પ્રયાસ કરો",
"oauthSignin": "સાઇન ઇન નિષ્ફળ ગઈ. કૃપા કરીને ફરી પ્રયાસ કરો, અથવા અલગ સાઇન ઇન પદ્ધતિ ઉપયોગ કરો.",
"redirectUriMismatch": "રીડાયરેક્ટ URI oauth ઍપ કન્ફિગરેશન સાથે મેળ ખાતો નથી",
"oauthCallback": "અલગ એકાઉન્ટથી સાઇન ઇન કરવાનો પ્રયાસ કરો",
"oauthCreateAccount": "અલગ એકાઉન્ટથી સાઇન ઇન કરવાનો પ્રયાસ કરો",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/he-IL.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "לא ניתן להתחבר",
"signin": "נסה להתחבר עם חשבון אחר",
"oauthSignin": "נסה להתחבר עם חשבון אחר",
"oauthSignin": "הכניסה נכשלה. אנא נסה שוב, או השתמש בשיטת כניסה אחרת.",
"redirectUriMismatch": "כתובת ההפניה אינה תואמת את תצורת אפליקציית OAuth",
"oauthCallback": "נסה להתחבר עם חשבון אחר",
"oauthCreateAccount": "נסה להתחבר עם חשבון אחר",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "साइन इन करने में असमर्थ",
"signin": "किसी दूसरे खाते से साइन इन करने का प्रयास करें",
"oauthSignin": "किसी दूसरे खाते से साइन इन करने का प्रयास करें",
"oauthSignin": "साइन इन विफल हुआ। कृपया पुनः प्रयास करें, या कोई अन्य साइन इन विधि उपयोग करें",
"redirectUriMismatch": "रीडायरेक्ट URI oauth ऐप कॉन्फ़िगरेशन से मेल नहीं खा रहा",
"oauthCallback": "किसी दूसरे खाते से साइन इन करने का प्रयास करें",
"oauthCreateAccount": "किसी दूसरे खाते से साइन इन करने का प्रयास करें",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "Impossibile effettuare l'accesso",
"signin": "Prova ad accedere con un account diverso",
"oauthSignin": "Prova ad accedere con un account diverso",
"oauthSignin": "Accesso non riuscito. Riprova o utilizza un metodo di accesso diverso.",
"redirectUriMismatch": "L'URI di reindirizzamento non corrisponde alla configurazione dell'app OAuth",
"oauthCallback": "Prova ad accedere con un account diverso",
"oauthCreateAccount": "Prova ad accedere con un account diverso",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "サインインできません",
"signin": "別のアカウントでサインインしてください",
"oauthSignin": "別のアカウントでサインインしてください",
"oauthSignin": "サインインに失敗しました。もう一度お試しいただくか、別のサインイン方法をお使いください。",
"redirectUriMismatch": "リダイレクトURIがOAuthアプリの設定と一致しません",
"oauthCallback": "別のアカウントでサインインしてください",
"oauthCreateAccount": "別のアカウントでサインインしてください",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/kn.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "ಸೈನ್ ಇನ್ ಮಾಡಲು ಸಾಧ್ಯವಾಗಲಿಲ್ಲ",
"signin": "ಬೇರೆ ಖಾತೆಯೊಂದಿಗೆ ಸೈನ್ ಇನ್ ಮಾಡಲು ಪ್ರಯತ್ನಿಸಿ",
"oauthSignin": "ಬೇರೆ ಖಾತೆಯೊಂದಿಗೆ ಸೈನ್ ಇನ್ ಮಾಡಲು ಪ್ರಯತ್ನಿಸಿ",
"oauthSignin": "ಸೈನ್ ಇನ್ ವಿಫಲವಾಗಿದೆ. ದಯವಿಟ್ಟು ಮತ್ತೆ ಪ್ರಯತ್ನಿಸಿ, ಅಥವಾ ಬೇರೆ ಸೈನ್ ಇನ್ ವಿಧಾನ ಬಳಸಿ.",
"redirectUriMismatch": "ರೀಡೈರೆಕ್ಟ್ URI ಓಥ್ ಅಪ್ಲಿಕೇಶನ್ ಕಾನ್ಫಿಗರೇಶನ್‌ಗೆ ಹೊಂದಿಕೆಯಾಗುತ್ತಿಲ್ಲ",
"oauthCallback": "ಬೇರೆ ಖಾತೆಯೊಂದಿಗೆ ಸೈನ್ ಇನ್ ಮಾಡಲು ಪ್ರಯತ್ನಿಸಿ",
"oauthCreateAccount": "ಬೇರೆ ಖಾತೆಯೊಂದಿಗೆ ಸೈನ್ ಇನ್ ಮಾಡಲು ಪ್ರಯತ್ನಿಸಿ",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "로그인할 수 없습니다",
"signin": "다른 계정으로 로그인해보세요",
"oauthSignin": "다른 계정으로 로그인해보세요",
"oauthSignin": "로그인에 실패했습니다. 다시 시도하거나 다른 로그인 방법을 사용해 주세요.",
"redirectUriMismatch": "리다이렉트 URI가 OAuth 앱 설정과 일치하지 않습니다",
"oauthCallback": "다른 계정으로 로그인해보세요",
"oauthCreateAccount": "다른 계정으로 로그인해보세요",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/ml.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "സൈൻ ഇൻ ചെയ്യാൻ കഴിയുന്നില്ല",
"signin": "മറ്റൊരു അക്കൗണ്ട് ഉപയോഗിച്ച് സൈൻ ഇൻ ചെയ്യാൻ ശ്രമിക്കുക",
"oauthSignin": "മറ്റൊരു അക്കൗണ്ട് ഉപയോഗിച്ച് സൈൻ ഇൻ ചെയ്യാൻ ശ്രമിക്കുക",
"oauthSignin": "സൈൻ ഇൻ പരാജയപ്പെട്ടു. ദയവായി വീണ്ടും ശ്രമിക്കുക, അല്ലെങ്കിൽ മറ്റൊരു സൈൻ ഇൻ രീതി ഉപയോഗിക്കുക.",
"redirectUriMismatch": "റീഡയറക്ട് URI oauth ആപ്പ് കോൺഫിഗറേഷനുമായി പൊരുത്തപ്പെടുന്നില്ല",
"oauthCallback": "മറ്റൊരു അക്കൗണ്ട് ഉപയോഗിച്ച് സൈൻ ഇൻ ചെയ്യാൻ ശ്രമിക്കുക",
"oauthCreateAccount": "മറ്റൊരു അക്കൗണ്ട് ഉപയോഗിച്ച് സൈൻ ഇൻ ചെയ്യാൻ ശ്രമിക്കുക",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/mr.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "साइन इन करू शकत नाही",
"signin": "वेगळ्या खात्याने साइन इन करण्याचा प्रयत्न करा",
"oauthSignin": "वेगळ्या खात्याने साइन इन करण्याचा प्रयत्न करा",
"oauthSignin": "साइन इन अयशस्वी झाले. कृपया पुन्हा प्रयत्न करा, किंवा वेगळी साइन इन पद्धत वापरा.",
"redirectUriMismatch": "रीडायरेक्ट URI ओथ अॅप कॉन्फिगरेशनशी जुळत नाही",
"oauthCallback": "वेगळ्या खात्याने साइन इन करण्याचा प्रयत्न करा",
"oauthCreateAccount": "वेगळ्या खात्याने साइन इन करण्याचा प्रयत्न करा",
Expand Down
2 changes: 1 addition & 1 deletion backend/chainlit/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"errors": {
"default": "Kan niet inloggen",
"signin": "Probeer in te loggen met een ander account",
"oauthSignin": "Probeer in te loggen met een ander account",
"oauthSignin": "Inloggen mislukt. Probeer het opnieuw of gebruik een andere aanmeldmethode.",
"redirectUriMismatch": "De redirect URI komt niet overeen met de oauth app configuratie",
"oauthCallback": "Probeer in te loggen met een ander account",
"oauthCreateAccount": "Probeer in te loggen met een ander account",
Expand Down
Loading
Loading