mirror of
https://github.com/open-webui/open-webui
synced 2025-01-18 00:30:51 +00:00
feat: Add OAuth Email Claim Variable
Add an `OAUTH_EMAIL_CLAIM` variable to override the default "email" claim value.
This commit is contained in:
parent
dbe463a53d
commit
d72d5d0e8e
@ -46,6 +46,7 @@ from config import (
|
|||||||
AppConfig,
|
AppConfig,
|
||||||
OAUTH_USERNAME_CLAIM,
|
OAUTH_USERNAME_CLAIM,
|
||||||
OAUTH_PICTURE_CLAIM,
|
OAUTH_PICTURE_CLAIM,
|
||||||
|
OAUTH_EMAIL_CLAIM,
|
||||||
)
|
)
|
||||||
|
|
||||||
from apps.socket.main import get_event_call, get_event_emitter
|
from apps.socket.main import get_event_call, get_event_emitter
|
||||||
@ -84,6 +85,7 @@ app.state.config.ENABLE_COMMUNITY_SHARING = ENABLE_COMMUNITY_SHARING
|
|||||||
|
|
||||||
app.state.config.OAUTH_USERNAME_CLAIM = OAUTH_USERNAME_CLAIM
|
app.state.config.OAUTH_USERNAME_CLAIM = OAUTH_USERNAME_CLAIM
|
||||||
app.state.config.OAUTH_PICTURE_CLAIM = OAUTH_PICTURE_CLAIM
|
app.state.config.OAUTH_PICTURE_CLAIM = OAUTH_PICTURE_CLAIM
|
||||||
|
app.state.config.OAUTH_EMAIL_CLAIM = OAUTH_EMAIL_CLAIM
|
||||||
|
|
||||||
app.state.MODELS = {}
|
app.state.MODELS = {}
|
||||||
app.state.TOOLS = {}
|
app.state.TOOLS = {}
|
||||||
|
@ -433,6 +433,12 @@ OAUTH_PICTURE_CLAIM = PersistentConfig(
|
|||||||
os.environ.get("OAUTH_PICTURE_CLAIM", "picture"),
|
os.environ.get("OAUTH_PICTURE_CLAIM", "picture"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
OAUTH_EMAIL_CLAIM = PersistentConfig(
|
||||||
|
"OAUTH_EMAIL_CLAIM",
|
||||||
|
"oauth.oidc.email_claim",
|
||||||
|
os.environ.get("OAUTH_EMAIL_CLAIM", "email"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_oauth_providers():
|
def load_oauth_providers():
|
||||||
OAUTH_PROVIDERS.clear()
|
OAUTH_PROVIDERS.clear()
|
||||||
|
@ -2158,7 +2158,8 @@ async def oauth_callback(provider: str, request: Request, response: Response):
|
|||||||
log.warning(f"OAuth callback failed, sub is missing: {user_data}")
|
log.warning(f"OAuth callback failed, sub is missing: {user_data}")
|
||||||
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
|
||||||
provider_sub = f"{provider}@{sub}"
|
provider_sub = f"{provider}@{sub}"
|
||||||
email = user_data.get("email", "").lower()
|
email_claim = webui_app.state.config.OAUTH_EMAIL_CLAIM
|
||||||
|
email = user_data.get(email_claim, "").lower()
|
||||||
# We currently mandate that email addresses are provided
|
# We currently mandate that email addresses are provided
|
||||||
if not email:
|
if not email:
|
||||||
log.warning(f"OAuth callback failed, email is missing: {user_data}")
|
log.warning(f"OAuth callback failed, email is missing: {user_data}")
|
||||||
|
Loading…
Reference in New Issue
Block a user