来自 POSTMAN 的 wso2 访问令牌验证 API 调用失败

wso2 access token validation API call from POSTMAN fails

我发现我们可以打这个电话

curl -k -u admin:admin -H 'Content-Type: application/x-www-form-urlencoded' -X POST --data 'token=fbc4e794-23db-3394-b1e5-f2c3e511d01f' https://localhost:9443/oauth2/introspect

检查访问令牌的有效性

这作为 curl 命令非常有效,但是当我将其导入 postman 并进行调用时,它失败了

它也不适用于 nodejs 代码

var axios = require('axios');
var qs = require('qs');
var data = qs.stringify({
  'token': 'ff744c77-53a6-46f2-ae4c-1da72cab52ab' 
});
var config = {
  method: 'post',
  url: 'https://localhost:9443/oauth2/introspect',
  headers: { 
    'Content-Type': 'application/x-www-form-urlencoded', 
    'Authorization': 'Basic YWRtaW46YWRtaW4='
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

你可以尝试将以下 curl 导入 postman

curl --location --request POST 'https://localhost:9443/oauth2/introspect' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'token=ff744c77-53a6-46f2-ae4c-1da72cab52ab'

如果在运行这段nodejs代码中出现如下错误:

{ Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (_tls_wrap.js:1058:34)
    at TLSSocket.emit (events.js:198:13)
    at TLSSocket._finishInit (_tls_wrap.js:636:8)
  code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
.
.
.
}

更新nodejs代码如下:

var axios = require('axios');
var https = require('https');
var qs = require('qs');
var data = qs.stringify({
  'token': 'ff744c77-53a6-46f2-ae4c-1da72cab52ab' 
});
var config = {
  method: 'post',
  url: 'https://localhost:9443/oauth2/introspect',
  headers: { 
    'Content-Type': 'application/x-www-form-urlencoded', 
    'Authorization': 'Basic YWRtaW46YWRtaW4='
  },
  data : data,
  httpsAgent: new https.Agent({
        rejectUnauthorized: false
    })
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

它应该return false/true(取决于访问令牌)如下:

{
    "active": false
}