oauth.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. import base64
  2. import logging
  3. import mimetypes
  4. import sys
  5. import uuid
  6. import json
  7. import aiohttp
  8. from authlib.integrations.starlette_client import OAuth
  9. from authlib.oidc.core import UserInfo
  10. from fastapi import (
  11. HTTPException,
  12. status,
  13. )
  14. from starlette.responses import RedirectResponse
  15. from open_webui.models.auths import Auths
  16. from open_webui.models.users import Users
  17. from open_webui.models.groups import Groups, GroupModel, GroupUpdateForm, GroupForm
  18. from open_webui.config import (
  19. DEFAULT_USER_ROLE,
  20. ENABLE_OAUTH_SIGNUP,
  21. OAUTH_MERGE_ACCOUNTS_BY_EMAIL,
  22. OAUTH_PROVIDERS,
  23. ENABLE_OAUTH_ROLE_MANAGEMENT,
  24. ENABLE_OAUTH_GROUP_MANAGEMENT,
  25. ENABLE_OAUTH_GROUP_CREATION,
  26. OAUTH_BLOCKED_GROUPS,
  27. OAUTH_ROLES_CLAIM,
  28. OAUTH_SUB_CLAIM,
  29. OAUTH_GROUPS_CLAIM,
  30. OAUTH_EMAIL_CLAIM,
  31. OAUTH_PICTURE_CLAIM,
  32. OAUTH_USERNAME_CLAIM,
  33. OAUTH_ALLOWED_ROLES,
  34. OAUTH_ADMIN_ROLES,
  35. OAUTH_ALLOWED_DOMAINS,
  36. OAUTH_UPDATE_PICTURE_ON_LOGIN,
  37. WEBHOOK_URL,
  38. JWT_EXPIRES_IN,
  39. AppConfig,
  40. )
  41. from open_webui.constants import ERROR_MESSAGES, WEBHOOK_MESSAGES
  42. from open_webui.env import (
  43. AIOHTTP_CLIENT_SESSION_SSL,
  44. WEBUI_NAME,
  45. WEBUI_AUTH_COOKIE_SAME_SITE,
  46. WEBUI_AUTH_COOKIE_SECURE,
  47. )
  48. from open_webui.utils.misc import parse_duration
  49. from open_webui.utils.auth import get_password_hash, create_token
  50. from open_webui.utils.webhook import post_webhook
  51. from open_webui.env import SRC_LOG_LEVELS, GLOBAL_LOG_LEVEL
  52. logging.basicConfig(stream=sys.stdout, level=GLOBAL_LOG_LEVEL)
  53. log = logging.getLogger(__name__)
  54. log.setLevel(SRC_LOG_LEVELS["OAUTH"])
  55. auth_manager_config = AppConfig()
  56. auth_manager_config.DEFAULT_USER_ROLE = DEFAULT_USER_ROLE
  57. auth_manager_config.ENABLE_OAUTH_SIGNUP = ENABLE_OAUTH_SIGNUP
  58. auth_manager_config.OAUTH_MERGE_ACCOUNTS_BY_EMAIL = OAUTH_MERGE_ACCOUNTS_BY_EMAIL
  59. auth_manager_config.ENABLE_OAUTH_ROLE_MANAGEMENT = ENABLE_OAUTH_ROLE_MANAGEMENT
  60. auth_manager_config.ENABLE_OAUTH_GROUP_MANAGEMENT = ENABLE_OAUTH_GROUP_MANAGEMENT
  61. auth_manager_config.ENABLE_OAUTH_GROUP_CREATION = ENABLE_OAUTH_GROUP_CREATION
  62. auth_manager_config.OAUTH_BLOCKED_GROUPS = OAUTH_BLOCKED_GROUPS
  63. auth_manager_config.OAUTH_ROLES_CLAIM = OAUTH_ROLES_CLAIM
  64. auth_manager_config.OAUTH_SUB_CLAIM = OAUTH_SUB_CLAIM
  65. auth_manager_config.OAUTH_GROUPS_CLAIM = OAUTH_GROUPS_CLAIM
  66. auth_manager_config.OAUTH_EMAIL_CLAIM = OAUTH_EMAIL_CLAIM
  67. auth_manager_config.OAUTH_PICTURE_CLAIM = OAUTH_PICTURE_CLAIM
  68. auth_manager_config.OAUTH_USERNAME_CLAIM = OAUTH_USERNAME_CLAIM
  69. auth_manager_config.OAUTH_ALLOWED_ROLES = OAUTH_ALLOWED_ROLES
  70. auth_manager_config.OAUTH_ADMIN_ROLES = OAUTH_ADMIN_ROLES
  71. auth_manager_config.OAUTH_ALLOWED_DOMAINS = OAUTH_ALLOWED_DOMAINS
  72. auth_manager_config.WEBHOOK_URL = WEBHOOK_URL
  73. auth_manager_config.JWT_EXPIRES_IN = JWT_EXPIRES_IN
  74. auth_manager_config.OAUTH_UPDATE_PICTURE_ON_LOGIN = OAUTH_UPDATE_PICTURE_ON_LOGIN
  75. class OAuthManager:
  76. def __init__(self, app):
  77. self.oauth = OAuth()
  78. self.app = app
  79. for _, provider_config in OAUTH_PROVIDERS.items():
  80. provider_config["register"](self.oauth)
  81. def get_client(self, provider_name):
  82. return self.oauth.create_client(provider_name)
  83. def get_user_role(self, user, user_data):
  84. user_count = Users.get_num_users()
  85. if user and user_count == 1:
  86. # If the user is the only user, assign the role "admin" - actually repairs role for single user on login
  87. log.debug("Assigning the only user the admin role")
  88. return "admin"
  89. if not user and user_count == 0:
  90. # If there are no users, assign the role "admin", as the first user will be an admin
  91. log.debug("Assigning the first user the admin role")
  92. return "admin"
  93. if auth_manager_config.ENABLE_OAUTH_ROLE_MANAGEMENT:
  94. log.debug("Running OAUTH Role management")
  95. oauth_claim = auth_manager_config.OAUTH_ROLES_CLAIM
  96. oauth_allowed_roles = auth_manager_config.OAUTH_ALLOWED_ROLES
  97. oauth_admin_roles = auth_manager_config.OAUTH_ADMIN_ROLES
  98. oauth_roles = []
  99. # Default/fallback role if no matching roles are found
  100. role = auth_manager_config.DEFAULT_USER_ROLE
  101. # Next block extracts the roles from the user data, accepting nested claims of any depth
  102. if oauth_claim and oauth_allowed_roles and oauth_admin_roles:
  103. claim_data = user_data
  104. nested_claims = oauth_claim.split(".")
  105. for nested_claim in nested_claims:
  106. claim_data = claim_data.get(nested_claim, {})
  107. oauth_roles = []
  108. if isinstance(claim_data, list):
  109. oauth_roles = claim_data
  110. if isinstance(claim_data, str) or isinstance(claim_data, int):
  111. oauth_roles = [str(claim_data)]
  112. log.debug(f"Oauth Roles claim: {oauth_claim}")
  113. log.debug(f"User roles from oauth: {oauth_roles}")
  114. log.debug(f"Accepted user roles: {oauth_allowed_roles}")
  115. log.debug(f"Accepted admin roles: {oauth_admin_roles}")
  116. # If any roles are found, check if they match the allowed or admin roles
  117. if oauth_roles:
  118. # If role management is enabled, and matching roles are provided, use the roles
  119. for allowed_role in oauth_allowed_roles:
  120. # If the user has any of the allowed roles, assign the role "user"
  121. if allowed_role in oauth_roles:
  122. log.debug("Assigned user the user role")
  123. role = "user"
  124. break
  125. for admin_role in oauth_admin_roles:
  126. # If the user has any of the admin roles, assign the role "admin"
  127. if admin_role in oauth_roles:
  128. log.debug("Assigned user the admin role")
  129. role = "admin"
  130. break
  131. else:
  132. if not user:
  133. # If role management is disabled, use the default role for new users
  134. role = auth_manager_config.DEFAULT_USER_ROLE
  135. else:
  136. # If role management is disabled, use the existing role for existing users
  137. role = user.role
  138. return role
  139. def update_user_groups(self, user, user_data, default_permissions):
  140. log.debug("Running OAUTH Group management")
  141. oauth_claim = auth_manager_config.OAUTH_GROUPS_CLAIM
  142. try:
  143. blocked_groups = json.loads(auth_manager_config.OAUTH_BLOCKED_GROUPS)
  144. except Exception as e:
  145. log.exception(f"Error loading OAUTH_BLOCKED_GROUPS: {e}")
  146. blocked_groups = []
  147. user_oauth_groups = []
  148. # Nested claim search for groups claim
  149. if oauth_claim:
  150. claim_data = user_data
  151. nested_claims = oauth_claim.split(".")
  152. for nested_claim in nested_claims:
  153. claim_data = claim_data.get(nested_claim, {})
  154. if isinstance(claim_data, list):
  155. user_oauth_groups = claim_data
  156. elif isinstance(claim_data, str):
  157. user_oauth_groups = [claim_data]
  158. else:
  159. user_oauth_groups = []
  160. user_current_groups: list[GroupModel] = Groups.get_groups_by_member_id(user.id)
  161. all_available_groups: list[GroupModel] = Groups.get_groups()
  162. # Create groups if they don't exist and creation is enabled
  163. if auth_manager_config.ENABLE_OAUTH_GROUP_CREATION:
  164. log.debug("Checking for missing groups to create...")
  165. all_group_names = {g.name for g in all_available_groups}
  166. groups_created = False
  167. # Determine creator ID: Prefer admin, fallback to current user if no admin exists
  168. admin_user = Users.get_super_admin_user()
  169. creator_id = admin_user.id if admin_user else user.id
  170. log.debug(f"Using creator ID {creator_id} for potential group creation.")
  171. for group_name in user_oauth_groups:
  172. if group_name not in all_group_names:
  173. log.info(
  174. f"Group '{group_name}' not found via OAuth claim. Creating group..."
  175. )
  176. try:
  177. new_group_form = GroupForm(
  178. name=group_name,
  179. description=f"Group '{group_name}' created automatically via OAuth.",
  180. permissions=default_permissions, # Use default permissions from function args
  181. user_ids=[], # Start with no users, user will be added later by subsequent logic
  182. )
  183. # Use determined creator ID (admin or fallback to current user)
  184. created_group = Groups.insert_new_group(
  185. creator_id, new_group_form
  186. )
  187. if created_group:
  188. log.info(
  189. f"Successfully created group '{group_name}' with ID {created_group.id} using creator ID {creator_id}"
  190. )
  191. groups_created = True
  192. # Add to local set to prevent duplicate creation attempts in this run
  193. all_group_names.add(group_name)
  194. else:
  195. log.error(
  196. f"Failed to create group '{group_name}' via OAuth."
  197. )
  198. except Exception as e:
  199. log.error(f"Error creating group '{group_name}' via OAuth: {e}")
  200. # Refresh the list of all available groups if any were created
  201. if groups_created:
  202. all_available_groups = Groups.get_groups()
  203. log.debug("Refreshed list of all available groups after creation.")
  204. log.debug(f"Oauth Groups claim: {oauth_claim}")
  205. log.debug(f"User oauth groups: {user_oauth_groups}")
  206. log.debug(f"User's current groups: {[g.name for g in user_current_groups]}")
  207. log.debug(
  208. f"All groups available in OpenWebUI: {[g.name for g in all_available_groups]}"
  209. )
  210. # Remove groups that user is no longer a part of
  211. for group_model in user_current_groups:
  212. if (
  213. user_oauth_groups
  214. and group_model.name not in user_oauth_groups
  215. and group_model.name not in blocked_groups
  216. ):
  217. # Remove group from user
  218. log.debug(
  219. f"Removing user from group {group_model.name} as it is no longer in their oauth groups"
  220. )
  221. user_ids = group_model.user_ids
  222. user_ids = [i for i in user_ids if i != user.id]
  223. # In case a group is created, but perms are never assigned to the group by hitting "save"
  224. group_permissions = group_model.permissions
  225. if not group_permissions:
  226. group_permissions = default_permissions
  227. update_form = GroupUpdateForm(
  228. name=group_model.name,
  229. description=group_model.description,
  230. permissions=group_permissions,
  231. user_ids=user_ids,
  232. )
  233. Groups.update_group_by_id(
  234. id=group_model.id, form_data=update_form, overwrite=False
  235. )
  236. # Add user to new groups
  237. for group_model in all_available_groups:
  238. if (
  239. user_oauth_groups
  240. and group_model.name in user_oauth_groups
  241. and not any(gm.name == group_model.name for gm in user_current_groups)
  242. and group_model.name not in blocked_groups
  243. ):
  244. # Add user to group
  245. log.debug(
  246. f"Adding user to group {group_model.name} as it was found in their oauth groups"
  247. )
  248. user_ids = group_model.user_ids
  249. user_ids.append(user.id)
  250. # In case a group is created, but perms are never assigned to the group by hitting "save"
  251. group_permissions = group_model.permissions
  252. if not group_permissions:
  253. group_permissions = default_permissions
  254. update_form = GroupUpdateForm(
  255. name=group_model.name,
  256. description=group_model.description,
  257. permissions=group_permissions,
  258. user_ids=user_ids,
  259. )
  260. Groups.update_group_by_id(
  261. id=group_model.id, form_data=update_form, overwrite=False
  262. )
  263. async def _process_picture_url(
  264. self, picture_url: str, access_token: str = None
  265. ) -> str:
  266. """Process a picture URL and return a base64 encoded data URL.
  267. Args:
  268. picture_url: The URL of the picture to process
  269. access_token: Optional OAuth access token for authenticated requests
  270. Returns:
  271. A data URL containing the base64 encoded picture, or "/user.png" if processing fails
  272. """
  273. if not picture_url:
  274. return "/user.png"
  275. try:
  276. get_kwargs = {}
  277. if access_token:
  278. get_kwargs["headers"] = {
  279. "Authorization": f"Bearer {access_token}",
  280. }
  281. async with aiohttp.ClientSession(trust_env=True) as session:
  282. async with session.get(
  283. picture_url, **get_kwargs, ssl=AIOHTTP_CLIENT_SESSION_SSL
  284. ) as resp:
  285. if resp.ok:
  286. picture = await resp.read()
  287. base64_encoded_picture = base64.b64encode(picture).decode(
  288. "utf-8"
  289. )
  290. guessed_mime_type = mimetypes.guess_type(picture_url)[0]
  291. if guessed_mime_type is None:
  292. guessed_mime_type = "image/jpeg"
  293. return (
  294. f"data:{guessed_mime_type};base64,{base64_encoded_picture}"
  295. )
  296. else:
  297. log.warning(
  298. f"Failed to fetch profile picture from {picture_url}"
  299. )
  300. return "/user.png"
  301. except Exception as e:
  302. log.error(f"Error processing profile picture '{picture_url}': {e}")
  303. return "/user.png"
  304. async def handle_login(self, request, provider):
  305. if provider not in OAUTH_PROVIDERS:
  306. raise HTTPException(404)
  307. # If the provider has a custom redirect URL, use that, otherwise automatically generate one
  308. redirect_uri = OAUTH_PROVIDERS[provider].get("redirect_uri") or request.url_for(
  309. "oauth_callback", provider=provider
  310. )
  311. client = self.get_client(provider)
  312. if client is None:
  313. raise HTTPException(404)
  314. return await client.authorize_redirect(request, redirect_uri)
  315. async def handle_callback(self, request, provider, response):
  316. if provider not in OAUTH_PROVIDERS:
  317. raise HTTPException(404)
  318. client = self.get_client(provider)
  319. try:
  320. token = await client.authorize_access_token(request)
  321. except Exception as e:
  322. log.warning(f"OAuth callback error: {e}")
  323. raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
  324. user_data: UserInfo = token.get("userinfo")
  325. if (
  326. (not user_data)
  327. or (auth_manager_config.OAUTH_EMAIL_CLAIM not in user_data)
  328. or (auth_manager_config.OAUTH_USERNAME_CLAIM not in user_data)
  329. ):
  330. user_data: UserInfo = await client.userinfo(token=token)
  331. if not user_data:
  332. log.warning(f"OAuth callback failed, user data is missing: {token}")
  333. raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
  334. if auth_manager_config.OAUTH_SUB_CLAIM:
  335. sub = user_data.get(auth_manager_config.OAUTH_SUB_CLAIM)
  336. else:
  337. # Fallback to the default sub claim if not configured
  338. sub = user_data.get(OAUTH_PROVIDERS[provider].get("sub_claim", "sub"))
  339. if not sub:
  340. log.warning(f"OAuth callback failed, sub is missing: {user_data}")
  341. raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
  342. provider_sub = f"{provider}@{sub}"
  343. email_claim = auth_manager_config.OAUTH_EMAIL_CLAIM
  344. email = user_data.get(email_claim, "")
  345. # We currently mandate that email addresses are provided
  346. if not email:
  347. # If the provider is GitHub,and public email is not provided, we can use the access token to fetch the user's email
  348. if provider == "github":
  349. try:
  350. access_token = token.get("access_token")
  351. headers = {"Authorization": f"Bearer {access_token}"}
  352. async with aiohttp.ClientSession(trust_env=True) as session:
  353. async with session.get(
  354. "https://api.github.com/user/emails",
  355. headers=headers,
  356. ssl=AIOHTTP_CLIENT_SESSION_SSL,
  357. ) as resp:
  358. if resp.ok:
  359. emails = await resp.json()
  360. # use the primary email as the user's email
  361. primary_email = next(
  362. (e["email"] for e in emails if e.get("primary")),
  363. None,
  364. )
  365. if primary_email:
  366. email = primary_email
  367. else:
  368. log.warning(
  369. "No primary email found in GitHub response"
  370. )
  371. raise HTTPException(
  372. 400, detail=ERROR_MESSAGES.INVALID_CRED
  373. )
  374. else:
  375. log.warning("Failed to fetch GitHub email")
  376. raise HTTPException(
  377. 400, detail=ERROR_MESSAGES.INVALID_CRED
  378. )
  379. except Exception as e:
  380. log.warning(f"Error fetching GitHub email: {e}")
  381. raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
  382. else:
  383. log.warning(f"OAuth callback failed, email is missing: {user_data}")
  384. raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
  385. email = email.lower()
  386. if (
  387. "*" not in auth_manager_config.OAUTH_ALLOWED_DOMAINS
  388. and email.split("@")[-1] not in auth_manager_config.OAUTH_ALLOWED_DOMAINS
  389. ):
  390. log.warning(
  391. f"OAuth callback failed, e-mail domain is not in the list of allowed domains: {user_data}"
  392. )
  393. raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
  394. # Check if the user exists
  395. user = Users.get_user_by_oauth_sub(provider_sub)
  396. if not user:
  397. # If the user does not exist, check if merging is enabled
  398. if auth_manager_config.OAUTH_MERGE_ACCOUNTS_BY_EMAIL:
  399. # Check if the user exists by email
  400. user = Users.get_user_by_email(email)
  401. if user:
  402. # Update the user with the new oauth sub
  403. Users.update_user_oauth_sub_by_id(user.id, provider_sub)
  404. if user:
  405. determined_role = self.get_user_role(user, user_data)
  406. if user.role != determined_role:
  407. Users.update_user_role_by_id(user.id, determined_role)
  408. # Update profile picture if enabled and different from current
  409. if auth_manager_config.OAUTH_UPDATE_PICTURE_ON_LOGIN:
  410. picture_claim = auth_manager_config.OAUTH_PICTURE_CLAIM
  411. if picture_claim:
  412. new_picture_url = user_data.get(
  413. picture_claim, OAUTH_PROVIDERS[provider].get("picture_url", "")
  414. )
  415. processed_picture_url = await self._process_picture_url(
  416. new_picture_url, token.get("access_token")
  417. )
  418. if processed_picture_url != user.profile_image_url:
  419. Users.update_user_profile_image_url_by_id(
  420. user.id, processed_picture_url
  421. )
  422. log.debug(f"Updated profile picture for user {user.email}")
  423. if not user:
  424. # If the user does not exist, check if signups are enabled
  425. if auth_manager_config.ENABLE_OAUTH_SIGNUP:
  426. # Check if an existing user with the same email already exists
  427. existing_user = Users.get_user_by_email(email)
  428. if existing_user:
  429. raise HTTPException(400, detail=ERROR_MESSAGES.EMAIL_TAKEN)
  430. picture_claim = auth_manager_config.OAUTH_PICTURE_CLAIM
  431. if picture_claim:
  432. picture_url = user_data.get(
  433. picture_claim, OAUTH_PROVIDERS[provider].get("picture_url", "")
  434. )
  435. picture_url = await self._process_picture_url(
  436. picture_url, token.get("access_token")
  437. )
  438. else:
  439. picture_url = "/user.png"
  440. username_claim = auth_manager_config.OAUTH_USERNAME_CLAIM
  441. name = user_data.get(username_claim)
  442. if not name:
  443. log.warning("Username claim is missing, using email as name")
  444. name = email
  445. role = self.get_user_role(None, user_data)
  446. user = Auths.insert_new_auth(
  447. email=email,
  448. password=get_password_hash(
  449. str(uuid.uuid4())
  450. ), # Random password, not used
  451. name=name,
  452. profile_image_url=picture_url,
  453. role=role,
  454. oauth_sub=provider_sub,
  455. )
  456. if auth_manager_config.WEBHOOK_URL:
  457. await post_webhook(
  458. WEBUI_NAME,
  459. auth_manager_config.WEBHOOK_URL,
  460. WEBHOOK_MESSAGES.USER_SIGNUP(user.name),
  461. {
  462. "action": "signup",
  463. "message": WEBHOOK_MESSAGES.USER_SIGNUP(user.name),
  464. "user": user.model_dump_json(exclude_none=True),
  465. },
  466. )
  467. else:
  468. raise HTTPException(
  469. status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.ACCESS_PROHIBITED
  470. )
  471. jwt_token = create_token(
  472. data={"id": user.id},
  473. expires_delta=parse_duration(auth_manager_config.JWT_EXPIRES_IN),
  474. )
  475. if auth_manager_config.ENABLE_OAUTH_GROUP_MANAGEMENT and user.role != "admin":
  476. self.update_user_groups(
  477. user=user,
  478. user_data=user_data,
  479. default_permissions=request.app.state.config.USER_PERMISSIONS,
  480. )
  481. redirect_base_url = str(request.app.state.config.WEBUI_URL or request.base_url)
  482. if redirect_base_url.endswith("/"):
  483. redirect_base_url = redirect_base_url[:-1]
  484. redirect_url = f"{redirect_base_url}/auth"
  485. response = RedirectResponse(url=redirect_url, headers=response.headers)
  486. # Set the cookie token
  487. # Redirect back to the frontend with the JWT token
  488. response.set_cookie(
  489. key="token",
  490. value=jwt_token,
  491. httponly=False, # Required for frontend access
  492. samesite=WEBUI_AUTH_COOKIE_SAME_SITE,
  493. secure=WEBUI_AUTH_COOKIE_SECURE,
  494. )
  495. if ENABLE_OAUTH_SIGNUP.value:
  496. oauth_id_token = token.get("id_token")
  497. response.set_cookie(
  498. key="oauth_id_token",
  499. value=oauth_id_token,
  500. httponly=True,
  501. samesite=WEBUI_AUTH_COOKIE_SAME_SITE,
  502. secure=WEBUI_AUTH_COOKIE_SECURE,
  503. )
  504. return response