Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
bbc8adca
Commit
bbc8adca
authored
Jul 19, 2024
by
Lukas
Browse files
support custom redirect url in OAuth
closes #3727 #3945
parent
82079e64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
backend/config.py
backend/config.py
+21
-0
backend/main.py
backend/main.py
+5
-1
No files found.
backend/config.py
View file @
bbc8adca
...
@@ -339,6 +339,12 @@ GOOGLE_OAUTH_SCOPE = PersistentConfig(
...
@@ -339,6 +339,12 @@ GOOGLE_OAUTH_SCOPE = PersistentConfig(
os
.
environ
.
get
(
"GOOGLE_OAUTH_SCOPE"
,
"openid email profile"
),
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
=
PersistentConfig
(
"MICROSOFT_CLIENT_ID"
,
"MICROSOFT_CLIENT_ID"
,
"oauth.microsoft.client_id"
,
"oauth.microsoft.client_id"
,
...
@@ -363,6 +369,12 @@ MICROSOFT_OAUTH_SCOPE = PersistentConfig(
...
@@ -363,6 +369,12 @@ MICROSOFT_OAUTH_SCOPE = PersistentConfig(
os
.
environ
.
get
(
"MICROSOFT_OAUTH_SCOPE"
,
"openid email profile"
),
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
=
PersistentConfig
(
"OAUTH_CLIENT_ID"
,
"OAUTH_CLIENT_ID"
,
"oauth.oidc.client_id"
,
"oauth.oidc.client_id"
,
...
@@ -381,6 +393,12 @@ OPENID_PROVIDER_URL = PersistentConfig(
...
@@ -381,6 +393,12 @@ OPENID_PROVIDER_URL = PersistentConfig(
os
.
environ
.
get
(
"OPENID_PROVIDER_URL"
,
""
),
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
=
PersistentConfig
(
"OAUTH_SCOPES"
,
"OAUTH_SCOPES"
,
"oauth.oidc.scopes"
,
"oauth.oidc.scopes"
,
...
@@ -414,6 +432,7 @@ def load_oauth_providers():
...
@@ -414,6 +432,7 @@ def load_oauth_providers():
"client_secret"
:
GOOGLE_CLIENT_SECRET
.
value
,
"client_secret"
:
GOOGLE_CLIENT_SECRET
.
value
,
"server_metadata_url"
:
"https://accounts.google.com/.well-known/openid-configuration"
,
"server_metadata_url"
:
"https://accounts.google.com/.well-known/openid-configuration"
,
"scope"
:
GOOGLE_OAUTH_SCOPE
.
value
,
"scope"
:
GOOGLE_OAUTH_SCOPE
.
value
,
"redirect_uri"
:
GOOGLE_REDIRECT_URI
.
value
,
}
}
if
(
if
(
...
@@ -426,6 +445,7 @@ def load_oauth_providers():
...
@@ -426,6 +445,7 @@ def load_oauth_providers():
"client_secret"
:
MICROSOFT_CLIENT_SECRET
.
value
,
"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"
,
"server_metadata_url"
:
f
"https://login.microsoftonline.com/
{
MICROSOFT_CLIENT_TENANT_ID
.
value
}
/v2.0/.well-known/openid-configuration"
,
"scope"
:
MICROSOFT_OAUTH_SCOPE
.
value
,
"scope"
:
MICROSOFT_OAUTH_SCOPE
.
value
,
"redirect_uri"
:
MICROSOFT_REDIRECT_URI
.
value
,
}
}
if
(
if
(
...
@@ -439,6 +459,7 @@ def load_oauth_providers():
...
@@ -439,6 +459,7 @@ def load_oauth_providers():
"server_metadata_url"
:
OPENID_PROVIDER_URL
.
value
,
"server_metadata_url"
:
OPENID_PROVIDER_URL
.
value
,
"scope"
:
OAUTH_SCOPES
.
value
,
"scope"
:
OAUTH_SCOPES
.
value
,
"name"
:
OAUTH_PROVIDER_NAME
.
value
,
"name"
:
OAUTH_PROVIDER_NAME
.
value
,
"redirect_uri"
:
OPENID_REDIRECT_URI
.
value
,
}
}
...
...
backend/main.py
View file @
bbc8adca
...
@@ -2111,6 +2111,7 @@ for provider_name, provider_config in OAUTH_PROVIDERS.items():
...
@@ -2111,6 +2111,7 @@ for provider_name, provider_config in OAUTH_PROVIDERS.items():
client_kwargs
=
{
client_kwargs
=
{
"scope"
:
provider_config
[
"scope"
],
"scope"
:
provider_config
[
"scope"
],
},
},
redirect_uri
=
provider_config
[
"redirect_uri"
],
)
)
# SessionMiddleware is used by authlib for oauth
# SessionMiddleware is used by authlib for oauth
...
@@ -2128,7 +2129,10 @@ if len(OAUTH_PROVIDERS) > 0:
...
@@ -2128,7 +2129,10 @@ if len(OAUTH_PROVIDERS) > 0:
async
def
oauth_login
(
provider
:
str
,
request
:
Request
):
async
def
oauth_login
(
provider
:
str
,
request
:
Request
):
if
provider
not
in
OAUTH_PROVIDERS
:
if
provider
not
in
OAUTH_PROVIDERS
:
raise
HTTPException
(
404
)
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
)
return
await
oauth
.
create_client
(
provider
).
authorize_redirect
(
request
,
redirect_uri
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment