2015-10-11 61 views
0

我试图从nodejs使用https request(尝试使用GETPOST方法)撤销销售团队令牌。撤销销售团队令牌nodejs

这是我GET method

var token = user.token; 
var uri = token.instanceUrl+'/services/oauth2/revoke?token='+token.accessToken; 
console.log("data: "+postData+", options: "+JSON.stringify(postOptions)+ ", \r\n" + uri); 
https.get(uri, function(response){ 
    var buffer = ''; 
    console.log(response.statusCode); 
    response.on('data', function (chunk) { 
     buffer += chunk; 
    }); 
    response.on('end', function(){ 
     console.log(buffer); 
    }); 
}); 

代码,但我不断获取此

error=unsupported_token_type&error_description=this%20token%20type%20is%20not%20supported, code: 400 

我也试图在浏览器的地址并获得400 Bad Request状态。

所有必需的选项已经根据销售人员的在线文档设置https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_revoke_token.htm&language=en

我缺少这使得它成为错误的请求?

回答

0

我向您展示如何使用request模块它做的事:

var request = require('request') 
request.post('https://login.salesforce.com/services/oauth2/revoke', { 
    form: { 
    token: '[ACCESS_TOKEN]' 
    }, 
    followAllRedirects: true 
}, function (err, res, body) {}) 

不知道网址,你正在试图用,但登录URL对于所有用户都是相同的,你不必使用你的实例子域。

而且从他们的文档注意这一点:

对于沙箱,而是使用login.salesforce.com的test.salesforce.com。

+0

我会试试这种方式。我正在使用实例URL,因为使用login.salesforce.com返回302状态码 – mynawaz

+0

相同的结果,'statusCode:400,body:'error = unsupported_token_type&error_description = this%20token%20type%20is%20not%20supported'' – mynawaz

+0

如果您是确定您传递的是'access_token',同时请注意,撤销方法仅适用于OAuth2,因此您必须确保在登录用户时使用的是OAuth2流。查看[这里](https://grant-oauth.herokuapp.com/#/linkedin2)​​ - [Grant](https://github.com/simov/grant)同时支持LinkedIn的OAuth1.0和OAuth2流。 – simo