不支持的赠款类型Salesforce OAUTH2

编程入门 行业动态 更新时间:2024-10-22 08:33:45
本文介绍了不支持的赠款类型Salesforce OAUTH2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用VBA在Salesforce中获得授权,然后最终希望运行Salesforce报表并将结果转储到Excel中.我已经编写了以下文件来处理授权,但是却收到unsupported_grant_type错误.到目前为止,我拥有的代码:

I am using VBA to get authorization in Salesforce and then ultimately want to run a Salesforce report and dump the results in Excel. I have written the following to handle the authorization, but I am getting an unsupported_grant_type error. The code I have so far:

Dim XMLHTTP As New MSXML2.XMLHTTP60 Dim username As String Dim password As String Dim PasswordnUsername As String Dim argumentString As String username = "myUsername" password = "myPassword" PasswordnUsername = password & ":" & username argumentString = "?grant_type=password&" & _ "client_id=abc123&" & _ "client_secret=123abc&" & _ "username=" & username & "&password=" & password MsgBox (argumentString) Set XMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0") XMLHTTP.Open "POST", "mysalesforce/services/oauth2/token", False XMLHTTP.setRequestHeader "content-type", "application/x-www-form-urlencoded" XMLHTTP.setRequestHeader "Authorization", "basic " + Base64Encode(PasswordnUsername) XMLHTTP.send (argumentString) MsgBox (XMLHTTP.responseText)

当我打印XMLHTTP.responseText时,这是报告unsupported_grant_type的地方.

When I print XMLHTTP.responseText, this is where the unsupported_grant_type is reported.

任何帮助将不胜感激.预先感谢.

Any help would be appreciated. Thanks in advance.

T

推荐答案

您正在使用用户名密码流" . URL中的所有参数,而不显示弹出窗口,让用户直接向SF输入其凭据(理想情况下,如果存在用户交互而不是后端系统互相交谈,则应使用另一个OAuth流程,因此您的应用无法处理密码,也无法泄漏密码).

You're using "Username-password flow". All params in the URL, without displaying a popup letting user type his credentials straight to SF (ideally if there's user interaction rather than backend systems talking to each other you're supposed to use another OAuth flow so your app doesn't handle passwords, can't leak them).

故障排除:

  • 确保您的请求中的username已编码.至少要放%40而不是@.如果您的尝试甚至没有出现在用户的登录历史记录中-用户名错误/编码错误.
  • 您可能还需要将安全令牌也静默地附加到密码上(再次查看用户的登录历史,也许有失败:需要API安全令牌").
  • 如果使用设置->我的域功能,请检查是否允许从通用login.salesforce登录.也许您的组织禁用了它,仅允许品牌登录域(也将影响API访问).也许您的管理员只允许从某些IP登录...
  • 您也无需添加Authorization: Basic +用户名&传递此调用,将其传递到POST的有效负载中就足够了.
  • Make sure username in your request is encoded. At very least put %40 instead of @. If your attempt doesn't even show up in user's login history - wrong / incorrectly encoded username.
  • You might need the security token also silently appended to the password (again, look into user's login history, maybe there's "Failed: API security token required").
  • If you use Setup -> My Domain feature, check whether you're allowed to log in from generic login.salesforce. Maybe your organisation disabled it and allows only the branded login domain (will impact API access too). Or maybe your admins allow logging in only from certain IPs...
  • Also you don't need to add Authorization: Basic + username & pass in this call, you pass it in POST's payload and that's enough.
  • 如果您有邮递员,curl,SoapUI或类似的客户端-在直接跳到VBA之前可能会有所帮助?

    If you have Postman, curl, SoapUI or any client like that - might help before jumping straight to VBA?

    这对我有用(带有Content-Type: application/x-www-form-urlencoded标头)

    This works for me (with Content-Type: application/x-www-form-urlencoded header)

    更多推荐

    不支持的赠款类型Salesforce OAUTH2

    本文发布于:2023-10-29 10:03:23,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1539408.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:赠款   不支持   类型   Salesforce

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!