简体   繁体   English

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

[英]wso2 access token validation API call from POSTMAN fails

I found that we can make this call我发现我们可以打这个电话

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 -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/内省

to check the validity of an access token检查访问令牌的有效性

This works perfectly as a curl command, but when i import this into postman and make calls,it fails这作为 curl 命令非常有效,但是当我将其导入 postman 并进行调用时,它失败了

it doesnt work from nodejs code also它也不适用于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);
});

If you get an error as follows while running this nodejs code:如果在运行这段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',
.
.
.
}

Update the nodejs code as follows:更新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);
});

It should return false/true (depending on the access token) as follows:它应该返回 false/true(取决于访问令牌),如下所示:

{
    "active": false
}

Can you try importing the following curl to postman您可以尝试将以下 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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM