具有 cookie 身份验证的 Reactivesearch proxylike 后端
Reactivesearch proxylike backend with cookie authentication
我有一个 spring 后端,我正在通过类似代理的端点访问我的 Elastic 搜索集群。请求必须通过 cookie 授权。
我目前使用的 searchkit 支持通过 withCredentials
标志对请求进行身份验证。 reactivesearch 是否有类似的选项,或者是否有任何其他解决方案可以使用 cookie 授权请求?
我可以补充:后端公开了一个 swagger 客户端,它在与我的前端客户端不同的域上运行。此客户端 "owns" cookie,因此我无法从我的前端客户端读取 cookie
您可以使用 ReactiveBase
中的 headers
道具来传递自定义 headers 以及请求。 Link 到文档。由于没有 withCredentials
,您可以读取 cookie 并在自定义 headers 中设置以验证代理中间件的请求。
<ReactiveBase
...
headers={{
customheader: 'abcxyz'
}}
>
<Component1 .. />
<Component2 .. />
</ReactiveBase>
Here 是一个示例代理服务器,但它在 NodeJS 中
好吧,事实证明,Reactivesearch 使用 fetch 和 fetch wants credentials: 'include'
进行 cookie 身份验证。这不能放在 Reactivesearch 提供的 headers 中,必须放在请求的根 object 中。
可以通过在 ReactiveBase 上实施 beforeSend
来做到这一点。
const Base = ({ children }) => {
const onBeforeSend = props => {
return {
...props,
credentials: 'include',
}
}
return (
<ReactiveBase
app="app-name"
url="url"
beforeSend={onBeforeSend}
>
{children}
</ReactiveBase>
)
}
我有一个 spring 后端,我正在通过类似代理的端点访问我的 Elastic 搜索集群。请求必须通过 cookie 授权。
我目前使用的 searchkit 支持通过 withCredentials
标志对请求进行身份验证。 reactivesearch 是否有类似的选项,或者是否有任何其他解决方案可以使用 cookie 授权请求?
我可以补充:后端公开了一个 swagger 客户端,它在与我的前端客户端不同的域上运行。此客户端 "owns" cookie,因此我无法从我的前端客户端读取 cookie
您可以使用 ReactiveBase
中的 headers
道具来传递自定义 headers 以及请求。 Link 到文档。由于没有 withCredentials
,您可以读取 cookie 并在自定义 headers 中设置以验证代理中间件的请求。
<ReactiveBase
...
headers={{
customheader: 'abcxyz'
}}
>
<Component1 .. />
<Component2 .. />
</ReactiveBase>
Here 是一个示例代理服务器,但它在 NodeJS 中
好吧,事实证明,Reactivesearch 使用 fetch 和 fetch wants credentials: 'include'
进行 cookie 身份验证。这不能放在 Reactivesearch 提供的 headers 中,必须放在请求的根 object 中。
可以通过在 ReactiveBase 上实施 beforeSend
来做到这一点。
const Base = ({ children }) => {
const onBeforeSend = props => {
return {
...props,
credentials: 'include',
}
}
return (
<ReactiveBase
app="app-name"
url="url"
beforeSend={onBeforeSend}
>
{children}
</ReactiveBase>
)
}