ValidationError:使用AzureAD进行hapi JS路由授权时不允许使用“ tenantId”

时间:2019-09-23 16:39:41

标签: azure azure-active-directory hapijs

我们正在尝试在后端路由上使用@ hapi / bell来提供授权。身份验证策略使用import React from "react"; import { Route, Switch } from "react-router-dom"; import Home from "./Home"; import SomeComponent from "./SomeComponent"; function AllRoutes() { return ( <Switch> <Route exact path="/" component={Home} /> <Route exact path="/someComp" component={SomeComponent} /> </Switch> ); } export default AllRoutes; 作为提供者,方案为azure

这就是我注册策略的方式。由于明显的原因,bellclientIdclientSecrettenantId被隐藏了

password

运行服务器时,出现以下错误:

server.auth.strategy('azureAD', 'bell', { provider: 'azure', clientId: '...', clientSecret: '...', tenantId: '...', password: '...', providerParams: { response_type: 'code' }, scope: ['openid', 'offline_access', 'profile', 'User.Read'] })

现在,进入天青门户网站,我们绝对希望仅在组织内部(即单租户)支持帐户。

如果我删除{ [ValidationError: "tenantId" is not allowed] ...选项并重新启动服务器,则会收到CORS错误,该错误实质上是我们的应用未配置为多租户应用,因此我们需要使用特定于租户的端点或配置该应用成为多租户。但是,添加tenantId表示不允许。

高度赞赏有关为什么发生这种情况的任何指导。

2 个答案:

答案 0 :(得分:2)

我发现,可以像在问题中所示的那样注册策略,而不要做以下操作:

const custom = Bell.providers.azure({ tenant: '...' })

server.auth.strategy('azureAD', 'bell', {
  provider: custom,
  clientId: '...',
  clientSecret: '...',
  password: '...',
  isSecure: false, // look into this, not a good idea but required if not using HTTPS
  providerParams: {
    response_type: 'code'
  },
  scope: ['openid', 'offline_access', 'profile', 'User.Read']
})

这摆脱了"tenantId"的错误,但是,我们现在得到了另一个错误,指出了Authentication failed due to: Missing custom request token cookie

Bell建议一种常见的解决方案是将bell与 hapi-auth-cookie 身份验证方案插件结合使用,因此现在值得研究。

答案 1 :(得分:0)

Joi软件包正在验证架构并引发错误。请参阅下面的config属性。它会覆盖选项,并避免出现“ tenantId”或“ tenant”错误。另外,在最新版本中,Bell Azure Provider希望使用“ tenant”而不是“ tenantId”属性。

server.auth.strategy('azureAD', 'bell', {
  provider: 'azure',
  config: {
    tenant: '...',
    useParamsAuth: false,
  },
  clientId: '...',
  clientSecret: '...',
  password: '...',
  providerParams: {
    response_type: 'code'
  },
  scope: ['openid', 'offline_access', 'profile', 'User.Read'],
  isSecure: false,
})