【问题标题】:Revoke salesforce token nodejs撤销 Salesforce 令牌 nodejs
【发布时间】:2015-10-12 00:20:58
【问题描述】:

我正在尝试使用 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 状态。

所有必需选项均已根据 Salesforce 在线文档https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_revoke_token.htm&language=en 进行设置

我缺少什么使其成为错误请求的原因?

【问题讨论】:

    标签: node.js oauth salesforce


    【解决方案1】:

    我正在向您展示如何使用 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,但所有用户的登录 URL 都是相同的,您不必使用您的实例子域。

    还要从他们的文档中注意到这一点:

    对于沙盒,使用 test.salesforce.com 而不是 login.salesforce.com。

    【讨论】:

    • 我会尝试这种方式。我正在使用实例 URL,因为使用 login.salesforce.com 返回 302 状态代码
    • 同样的结果,statusCode: 400, body: 'error=unsupported_token_type&error_description=this%20token%20type%20is%20not%20supported'
    • 如果您确定您通过了access_token,还请注意,撤销方法仅适用于 OAuth2,因此您必须确保在登录用户时使用 OAuth2 流程。查看here -- Grant 支持 LinkedIn 的 OAuth1.0 和 OAuth2 流。
    • 是的,使用 oauth2 和 access_token。当我在浏览器中访问此地址时得到相同结果的这一点意味着它必须与 salesforce 或应用程序设置有关。我已启用Perform requests on your behalf at any time 权限。您是否知道启用撤销是否需要任何特定设置/权限?
    • 看看这个screenshot,这就是成功撤销的样子。 Salesforce 实际上会将您重定向到您的实例域。如果我再次执行相同的代码,我会得到和你一样的错误,所以我假设你的access_token 已经被撤销了。我还更新了我的答案,您需要再设置一个请求选项 - followAllRedirects: true
    猜你喜欢
    • 2019-04-12
    • 1970-01-01
    • 2014-06-06
    • 2021-09-24
    • 1970-01-01
    • 2015-11-02
    • 2020-09-29
    相关资源
    最近更新 更多