Reactivesearch proxylike backend with cookie authentication

落爺英雄遲暮 提交于 2019-12-23 01:35:17

问题


I have a spring backend which i'm accessing my Elastic search cluster through by a proxylike endpoint. The request has to be authorized with a cookie.

I'm currently using searchkit with supports authenticating requests through the withCredentials flag. Is there a similar option for reactivesearch or is there any other solution for authorizing the request with a cookie?

I could add: the backend exposes a swagger client which runs on a different domain than my frontend client. This client "owns" the cookie and thus i cannot read the cookie from my frontend client


回答1:


Okey so it turns out, Reactivesearch uses fetch and fetch wants credentials: 'include' for cookie authentication. This may not be placed in the headers that Reactivesearch supplies and must be placed on the root object for the request.

It's possible to do this by implementing beforeSend on ReactiveBase.

const Base = ({ children }) => {
  const onBeforeSend = props => {
    return {
      ...props,
      credentials: 'include',
    }
  }

  return (
    <ReactiveBase
      app="app-name"
      url="url"
      beforeSend={onBeforeSend}
    >
      {children}
    </ReactiveBase>
  )
}



回答2:


You can use the headers prop in ReactiveBase to pass custom headers along with the requests. Link to docs. Since there is no withCredentials you could read the cookies and set in custom headers to verify the requests at the proxy middleware.

<ReactiveBase
  ...
  headers={{
      customheader: 'abcxyz'
  }}
>
    <Component1 .. />
    <Component2 .. />
</ReactiveBase>

Here is a sample proxy server but its in NodeJS



来源:https://stackoverflow.com/questions/51724753/reactivesearch-proxylike-backend-with-cookie-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!