2015-10-11 84 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