如何将 windows 身份验证(浏览器)从 React 应用程序传递到 Spnego Kerberos Spring SSO?

How to pass windows authentication(browser) from react application to Spnego Kerberos Spring SSO?

我们有一个 React 应用程序,它用于从 spring 引导网络服务获取数据。两者都部署在同一台服务器上(tomcat)。但是对于来自 React 应用程序的 Web 服务调用,我们只需要 Kerberos 身份验证。任何人都可以打开 React 应用程序,但是当它导航时,它会调用 webservcie 来获取数据。因此,如果我们配置 spring 以支持 spnego kerberos spring sso,浏览器是否有可能自动通过(来自 React 应用程序,作为浏览器上的 react 运行)登录 Windows spring 引导 Web 服务的凭据。

我们正在从 React 应用调用服务,如下所示 -

export const client = rest
  .wrap(mime, { registry: registry })
  .wrap(errorCode)
  .wrap(defaultRequest, {
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json'
    },
    method: 'GET'
  })



export const fetchPDSIs = (Id) =>
  APIHelpers.client(APIHelpers.buildPDSIReq(Id))
    .then(
      response => (response.entity || []).sort((a, b) => a.portalinstance.localeCompare(b.portalinstance))
      ,
      response => {
        global.msg.error(<div className='smallTextNotification'>`Fetching instances and portal for {Id} error: {response.status.code} -> {response.status.text}</div>)
        return []
      }
    )

export const buildPDSIReq = (Id) => ({path: `${serverAddr}/msd232/pdsiii/${Id}`})

可以,客户端要求:

  1. 用户在 OS 上登录域帐户。
  2. 浏览器正确配置,见Spring documentation

例如对于 Internet Explorer:

E.3 Internet Explorer

Complete following steps to ensure that your Internet Explorer browser is enabled to perform Spnego authentication.

Open Internet Explorer.
Click Tools > Intenet Options > Security tab.
In Local intranet section make sure your server is trusted by i.e. adding it into a list.

Kerberos 身份验证由从后端服务返回的 HTTP header 触发:

WWW-Authenticate: Negotiate

如果您的 OS 和浏览器配置正确,这将触发服务票证生成,该浏览器将作为 Authorization HTTP header 值发送。

编辑: 如果您的应用程序分为前端和后端分别托管在不同的主机上,那么您必须为用户将进入的前端主机注册 SPN(并生成密钥表)。示例:

  • 后端:api.test.com
  • 前端:application.test.com

要使 SSO 工作,您必须注册 SPN:application.test.com,后端主机名与此处无关。命令:

setspn -A HTTP/application.test.com@test.com ad_user_to_registern_spn_for 

使用提取 API,它通过添加凭据对我有用:'include'

获取(${authBase}/auth,{凭据:'include'})

我知道你用的不是这个,但它可能对其他读者有帮助