验证错误:使用 AzureAD 进行满意 JS 路由授权时不允许"tenantId"



我们正尝试在后端路由上使用@hapi/bell来提供授权。身份验证策略使用azure作为提供程序,方案bell

这就是我注册策略的方式。clientIdclientSecrettenantIdpassword被隐藏,原因显而易见

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] ...

现在,查看 Azure 门户,我们肯定希望仅支持组织内部的帐户,即单租户。

如果我删除tenantId选项并重新启动服务器,则会收到 CORS 错误,这实质上是说我们的应用未配置为多租户应用程序,我们需要使用特定于租户的终结点或将应用程序配置为多租户。但是,添加tenantId表示不允许这样做。

任何关于为什么会发生这种情况的指导将不胜感激。

我发现,与其像问题中所示那样注册策略,不如执行以下操作:

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 与happy-auth-cookie身份验证方案插件相结合,所以现在这是值得研究的事情。

Joi 包正在验证架构并引发错误。 请参阅下面的配置属性。 它会覆盖选项并避免您看到的"租户 ID"或"租户不允许"错误。此外,在最新版本中,贝尔 Azure 提供程序需要"租户"而不是"租户 Id"属性。

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,
})

最新更新