openid-client wso2 401 未经授权

openid-client wso2 401 Unauthorized

我尝试使用 node-openid-client 从 wso2 身份服务器获取访问代码。 我如何发送身份验证凭据?

'use strict';

const { Issuer } = require('openid-client');
Issuer.discover('https://localhost:9443/oauth2/oidcdiscovery') // => Promise
  .then(function (wso2Issuer) {
    console.log('Discovered wso2Issuer %s', wso2Issuer);
  });

我的结果:

node:23516) UnhandledPromiseRejectionWarning: AggregateError:
    OPError: expected 200 OK, got: 401 Unauthorized

我假设此 Issuer.discover 方法正在尝试访问 /.well-known 端点。 你得到 401 Unauthorized 的原因是因为在 WSO2 IS 5.7.0 中这个端点默认是安全的。

您的问题有两种解决方案

  1. 使用 base64 编码的用户凭据发送授权:基本 header。即:Authorization: Basic base64encoded(username:password)
  2. 使端点不安全。

因为这是一个发现端点,我会说选择选项 2。

  • 您可以通过执行以下操作使此端点不安全;打开 identity.xml 文件在 <IS-HOME>/repository/conf/identity/ 和 找到 <ResourceAccessControl> 标签。
  • 在该标签内,您可以找到匹配 <Resource context="(.*)/.well-known(.*)" secured="true" http-method="all"/> 的资源,设置为 false。 即:<Resource context="(.*)/.well-known(.*)" secured="false" http-method="all"/>

您需要重新启动服务器才能使配置更改生效。