mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-11 22:52:54 +00:00
refac
This commit is contained in:
parent
b71744b178
commit
3cda47cdb4
3 changed files with 51 additions and 8 deletions
|
|
@ -145,15 +145,13 @@ async def build_tool_server_headers(
|
|||
|
||||
auth_type = connection.get('auth_type', 'bearer')
|
||||
headers = {}
|
||||
cookies = {}
|
||||
cookies = getattr(request, 'cookies', {}) if connection.get('forward_cookies', False) else {}
|
||||
|
||||
if auth_type == 'bearer':
|
||||
headers.update(bearer_auth_header(connection.get('key', '')))
|
||||
elif auth_type == 'session':
|
||||
cookies = request.cookies if hasattr(request, 'cookies') else {}
|
||||
headers.update(bearer_auth_header(request.state.token.credentials))
|
||||
elif auth_type == 'system_oauth':
|
||||
cookies = request.cookies if hasattr(request, 'cookies') else {}
|
||||
oauth_token = extra_params.get('__oauth_token__', None)
|
||||
if oauth_token:
|
||||
headers.update(bearer_auth_header(oauth_token.get('access_token', '')))
|
||||
|
|
@ -1393,16 +1391,14 @@ async def get_terminal_tools(
|
|||
|
||||
# Build auth headers
|
||||
auth_type = connection.get('auth_type', 'bearer')
|
||||
cookies = {}
|
||||
cookies = getattr(request, 'cookies', {}) if connection.get('forward_cookies', False) else {}
|
||||
headers = {'Content-Type': 'application/json', 'X-User-Id': user.id}
|
||||
|
||||
if auth_type == 'bearer':
|
||||
headers.update(bearer_auth_header(connection.get('key', '')))
|
||||
elif auth_type == 'session':
|
||||
cookies = request.cookies
|
||||
headers.update(bearer_auth_header(request.state.token.credentials))
|
||||
elif auth_type == 'system_oauth':
|
||||
cookies = request.cookies
|
||||
oauth_token = extra_params.get('__oauth_token__', None)
|
||||
if oauth_token:
|
||||
headers.update(bearer_auth_header(oauth_token.get('access_token', '')))
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import Modal from '$lib/components/common/Modal.svelte';
|
||||
import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
|
||||
import Switch from '$lib/components/common/Switch.svelte';
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
import AccessControlModal from '$lib/components/workspace/common/AccessControlModal.svelte';
|
||||
import AccessButton from '$lib/components/common/AccessButton.svelte';
|
||||
|
|
@ -34,6 +35,7 @@
|
|||
let name = '';
|
||||
let id = '';
|
||||
let auth_type = 'bearer';
|
||||
let forwardCookies = false;
|
||||
let path = '/openapi.json';
|
||||
let enabled = false;
|
||||
let chatUploads: 'default' | 'filesystem' = 'default';
|
||||
|
|
@ -73,6 +75,7 @@
|
|||
};
|
||||
|
||||
const init = () => {
|
||||
forwardCookies = connection?.forward_cookies ?? false;
|
||||
if (connection) {
|
||||
id = connection?.id ?? '';
|
||||
url = connection.url;
|
||||
|
|
@ -125,6 +128,7 @@
|
|||
key = '';
|
||||
name = '';
|
||||
auth_type = 'bearer';
|
||||
forwardCookies = false;
|
||||
path = '/openapi.json';
|
||||
enabled = false;
|
||||
chatUploads = 'default';
|
||||
|
|
@ -393,6 +397,7 @@
|
|||
name,
|
||||
path,
|
||||
auth_type,
|
||||
...(!direct ? { forward_cookies: forwardCookies } : {}),
|
||||
enabled: enabled,
|
||||
config: connectionConfig,
|
||||
// Policy fields
|
||||
|
|
@ -874,6 +879,24 @@
|
|||
</div>
|
||||
|
||||
{#if showAdvanced}
|
||||
{#if !direct}
|
||||
<div class="flex items-center justify-between gap-3 mt-2">
|
||||
<div>
|
||||
<label for="forward-cookies" class="text-xs text-gray-500">
|
||||
{$i18n.t('Forward cookies')}
|
||||
</label>
|
||||
<p class="text-xs text-gray-500">
|
||||
{$i18n.t('Forward cookies from your Open WebUI request to this server.')}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="forward-cookies"
|
||||
ariaLabel={$i18n.t('Forward cookies')}
|
||||
bind:state={forwardCookies}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex gap-2 mt-2">
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex justify-between items-center mb-0.5">
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { getContext, onMount } from 'svelte';
|
||||
const i18n = getContext('i18n');
|
||||
const i18n = getContext<any>('i18n');
|
||||
|
||||
import Modal from '$lib/components/common/Modal.svelte';
|
||||
import Plus from '$lib/components/icons/Plus.svelte';
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
export let edit = false;
|
||||
|
||||
export let direct = false;
|
||||
export let connection = null;
|
||||
export let connection: any = null;
|
||||
|
||||
let inputElement = null;
|
||||
|
||||
|
|
@ -49,6 +49,7 @@
|
|||
let path = 'openapi.json';
|
||||
|
||||
let auth_type = 'bearer';
|
||||
let forwardCookies = false;
|
||||
let key = '';
|
||||
let headers = '';
|
||||
|
||||
|
|
@ -264,6 +265,7 @@
|
|||
if (data.path) path = data.path;
|
||||
|
||||
if (data.auth_type) auth_type = data.auth_type;
|
||||
forwardCookies = data.forward_cookies ?? false;
|
||||
if (data.headers) headers = JSON.stringify(data.headers, null, 2);
|
||||
if (data.key) key = data.key;
|
||||
|
||||
|
|
@ -300,6 +302,7 @@
|
|||
path,
|
||||
|
||||
auth_type,
|
||||
...(!direct && ['', 'openapi'].includes(type) ? { forward_cookies: forwardCookies } : {}),
|
||||
headers: headers ? JSON.parse(headers) : undefined,
|
||||
key,
|
||||
|
||||
|
|
@ -380,6 +383,7 @@
|
|||
path,
|
||||
|
||||
auth_type,
|
||||
...(!direct && ['', 'openapi'].includes(type) ? { forward_cookies: forwardCookies } : {}),
|
||||
headers: headers ? JSON.parse(headers) : undefined,
|
||||
|
||||
key,
|
||||
|
|
@ -424,6 +428,7 @@
|
|||
|
||||
key = '';
|
||||
auth_type = 'bearer';
|
||||
forwardCookies = false;
|
||||
|
||||
id = '';
|
||||
name = '';
|
||||
|
|
@ -442,6 +447,7 @@
|
|||
};
|
||||
|
||||
const init = () => {
|
||||
forwardCookies = connection?.forward_cookies ?? false;
|
||||
if (connection) {
|
||||
type = connection?.type ?? 'openapi';
|
||||
url = connection.url;
|
||||
|
|
@ -848,6 +854,24 @@
|
|||
</div>
|
||||
|
||||
{#if showAdvanced}
|
||||
{#if !direct && ['', 'openapi'].includes(type)}
|
||||
<div class="flex items-center justify-between gap-3 mt-2">
|
||||
<div>
|
||||
<label for="forward-cookies" class="text-xs text-gray-500">
|
||||
{$i18n.t('Forward cookies')}
|
||||
</label>
|
||||
<p class="text-xs text-gray-500">
|
||||
{$i18n.t('Forward cookies from your Open WebUI request to this server.')}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="forward-cookies"
|
||||
ariaLabel={$i18n.t('Forward cookies')}
|
||||
bind:state={forwardCookies}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if ['', 'openapi'].includes(type)}
|
||||
<div class="flex gap-2 mt-2">
|
||||
<div class="flex flex-col w-full">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue