node.js - openid-client wso2 401 未经授权
问题描述
我尝试使用 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 中这个端点默认是安全的。
您的问题有两种解决方案
- 使用 base64 编码的用户凭据发送 Authorization: Basic 标头。IE:
Authorization: Basic base64encoded(username:password)
- 使端点不安全。
由于这是一个发现端点,我会说选择选项 2。
- 您可以通过执行以下操作使此端点不安全;打开
identity.xml
里面的文件<IS-HOME>/repository/conf/identity/
并找到<ResourceAccessControl>
标签。 - 在该标签内,您可以找到一个资源匹配
<Resource context="(.*)/.well-known(.*)" secured="true" http-method="all"/>
集,保护为false
. IE:<Resource context="(.*)/.well-known(.*)" secured="false" http-method="all"/>
您需要重新启动服务器才能使配置更改生效。
推荐阅读
- flutter - 如何将元素添加到现有的地图 Firestore
- javascript - 发送服务器请求 api 时返回服务器错误
- tensorflow - 强制深度自动编码器过拟合训练数据
- react-native - React Native 参数未更新
- python - “如何在 python 中对 bin 文件进行统计分析?”
- apache-spark - 将 DataFrame 写入 HDFS,连接被拒绝
- python - 我的数据库查询输出中的“< >”是什么意思?
- c - 如何将一个文件的内容复制到另一个文件
- scala - 当我们可以从中添加或删除元素时,地图或列表如何是不可变的?
- python - 获取二叉树的所有分支(从根到叶)作为 Python 中的列表