From bbc8adca9433939135ea700ff17b75ab1f6aebb1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 19 Jul 2024 09:03:41 +0200 Subject: [PATCH 01/28] support custom redirect url in OAuth closes #3727 #3945 --- backend/config.py | 21 +++++++++++++++++++++ backend/main.py | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/backend/config.py b/backend/config.py index fe68eee34..4dedb8a87 100644 --- a/backend/config.py +++ b/backend/config.py @@ -339,6 +339,12 @@ GOOGLE_OAUTH_SCOPE = PersistentConfig( os.environ.get("GOOGLE_OAUTH_SCOPE", "openid email profile"), ) +GOOGLE_REDIRECT_URI = PersistentConfig( + "GOOGLE_REDIRECT_URI", + "oauth.google.redirect_uri", + os.environ.get("GOOGLE_REDIRECT_URI", ""), +) + MICROSOFT_CLIENT_ID = PersistentConfig( "MICROSOFT_CLIENT_ID", "oauth.microsoft.client_id", @@ -363,6 +369,12 @@ MICROSOFT_OAUTH_SCOPE = PersistentConfig( os.environ.get("MICROSOFT_OAUTH_SCOPE", "openid email profile"), ) +MICROSOFT_REDIRECT_URI = PersistentConfig( + "MICROSOFT_REDIRECT_URI", + "oauth.microsoft.redirect_uri", + os.environ.get("MICROSOFT_REDIRECT_URI", ""), +) + OAUTH_CLIENT_ID = PersistentConfig( "OAUTH_CLIENT_ID", "oauth.oidc.client_id", @@ -381,6 +393,12 @@ OPENID_PROVIDER_URL = PersistentConfig( os.environ.get("OPENID_PROVIDER_URL", ""), ) +OPENID_REDIRECT_URI = PersistentConfig( + "OPENID_REDIRECT_URI", + "oauth.oidc.redirect_uri", + os.environ.get("OPENID_REDIRECT_URI", ""), +) + OAUTH_SCOPES = PersistentConfig( "OAUTH_SCOPES", "oauth.oidc.scopes", @@ -414,6 +432,7 @@ def load_oauth_providers(): "client_secret": GOOGLE_CLIENT_SECRET.value, "server_metadata_url": "https://accounts.google.com/.well-known/openid-configuration", "scope": GOOGLE_OAUTH_SCOPE.value, + "redirect_uri": GOOGLE_REDIRECT_URI.value, } if ( @@ -426,6 +445,7 @@ def load_oauth_providers(): "client_secret": MICROSOFT_CLIENT_SECRET.value, "server_metadata_url": f"https://login.microsoftonline.com/{MICROSOFT_CLIENT_TENANT_ID.value}/v2.0/.well-known/openid-configuration", "scope": MICROSOFT_OAUTH_SCOPE.value, + "redirect_uri": MICROSOFT_REDIRECT_URI.value, } if ( @@ -439,6 +459,7 @@ def load_oauth_providers(): "server_metadata_url": OPENID_PROVIDER_URL.value, "scope": OAUTH_SCOPES.value, "name": OAUTH_PROVIDER_NAME.value, + "redirect_uri": OPENID_REDIRECT_URI.value, } diff --git a/backend/main.py b/backend/main.py index 62f07a868..2ee4fad06 100644 --- a/backend/main.py +++ b/backend/main.py @@ -2111,6 +2111,7 @@ for provider_name, provider_config in OAUTH_PROVIDERS.items(): client_kwargs={ "scope": provider_config["scope"], }, + redirect_uri=provider_config["redirect_uri"], ) # SessionMiddleware is used by authlib for oauth @@ -2128,7 +2129,10 @@ if len(OAUTH_PROVIDERS) > 0: async def oauth_login(provider: str, request: Request): if provider not in OAUTH_PROVIDERS: raise HTTPException(404) - redirect_uri = request.url_for("oauth_callback", provider=provider) + # If the provider has a custom redirect URL, use that, otherwise automatically generate one + redirect_uri = OAUTH_PROVIDERS[provider].get("redirect_url") or request.url_for( + "oauth_callback", provider=provider + ) return await oauth.create_client(provider).authorize_redirect(request, redirect_uri) From f83c80aaec341dc35d67607d42d47069c24479db Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 19 Jul 2024 09:08:46 +0200 Subject: [PATCH 02/28] add changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3bceff25..046ba7fb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- Ability to override default redirect urls when using OAuth with environment variables. You may use `OAUTH_REDIRECT_URL`, `MICROSOFT_REDIRECT_URL`, or `GOOGLE_REDIRECT_URL` to set custom redirect URLs. + ## [0.3.10] - 2024-07-17 ### Fixed From 6681df29d27e1d56baabadfbac5492e509870137 Mon Sep 17 00:00:00 2001 From: Clivia <132346501+Yanyutin753@users.noreply.github.com> Date: Wed, 31 Jul 2024 07:25:53 +0800 Subject: [PATCH 03/28] =?UTF-8?q?=E2=9A=A1Initialize=20fileItem=20first=20?= =?UTF-8?q?to=20speed=20up=20file=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/components/chat/MessageInput.svelte | 71 ++++++++++++--------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index 5ea541c7f..e59e917e1 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -1,5 +1,6 @@