从streamlit中的HTTP标头中提取bearerToken

问题描述 投票:0回答:1

下面是我的 React 应用程序代码,根据应用程序逻辑,我将其路由到在不同服务器上运行的 Streamlit 应用程序。

我们希望在 Streamlit 应用程序中对用户进行身份验证。因此,我们将 bearerToken 作为查询参数的一部分发送到 url 中,如下所示。

使用 window.location.href 路由到 Streamlit 应用程序并发送 bearerToken

window.location.href = `http://streamlit_url?key=` + bearerToken

我们使用以下代码从 Streamlit 中的查询参数接收 bearerToken 并验证用户:

query_params = st.experimental_get_query_params()
token = query_params["key"]

将 bearerToken 作为查询参数的一部分发送存在安全问题。

有人可以协助如何通过 React UI 组件中的 HTTP 标头参数发送不记名令牌并将其路由到 Streamlit 应用程序。因此,可以在 Streamlit 应用程序中接收 bearerToken 并且可以验证用户。 或者 请提出替代解决方案。

python reactjs http streamlit
1个回答
0
投票

您可以通过标头发送。

fetch('http://streamlit_url', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${bearerToken}`
  }
})
.then(response => {
  if (response.ok) {
     window.location.href = 'http://streamlit_url';
   }
© www.soinside.com 2019 - 2024. All rights reserved.