首页 > 解决方案 > 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

标签: node.jswso2wso2is

解决方案


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

您的问题有两种解决方案

  1. 使用 base64 编码的用户凭据发送 Authorization: Basic 标头。IE: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. IE:<Resource context="(.*)/.well-known(.*)" secured="false" http-method="all"/>

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


推荐阅读