无法从Mule Salesforce获取访问令牌

Bre*_*een 5 salesforce mule oauth-2.0

尝试从SalesForce获取访问令牌时,我无法获取访问令牌.我输入了https:// localhost:8081/AppCallback的回调URL .但是,当我打印出令牌时,我在浏览器中显示为null.当我更改消费者密钥值时,我仍然获得成功,但似乎我没有点击该服务.这是我的配置.我发送请求到http:// localhost:8081/authorize然后我回来了

您已成功授权连接器.您的访问令牌ID为:null

   <http:listener-config name="HTTP_Listener_Configuration"
            host="localhost" port="8081" doc:name="HTTP Listener 
    Configuration" />

        <sfdc:config-with-oauth name="salesforce-oauth"
            onNoToken="EXCEPTION"
       accessTokenUrl="https://app.my.salesforce.com/services/oauth2/token"

     authorizationUrl="https://app.my.salesforce.com/services/oauth2/authorize"
            consumerKey="myConsumerKey"
            consumerSecret="33388E8E" doc:name="Salesforce (OAuth)">
            <sfdc:oauth-callback-config domain="localhost"
                localPort="8081" remotePort="8081" path="AppCallBack" />
        </sfdc:config-with-oauth>

   <flow name="authorize" doc:name="authorize">
            <http:listener config-ref="HTTP_Listener_Configuration"  allowedMethods="GET" 
                path="authorize" doc:name="HTTP">
                <http:response-builder statusCode="200" reasonPhrase="You have successfully authorized the connector. Your access token id is: #[flowVars.OAuthAccessTokenId]" />
                <http:error-response-builder statusCode="404" reasonPhrase="An error has occurred authorizing the connector" />
            </http:listener>
            <sfdc:authorize immediate="TRUE" config-ref="salesforce-oauth"  display="PAGE" doc:name="Authorize at Salesforce" />
        </flow>

  <flow name="sfdctestFlow1" doc:name="readContactFlow1">
            <http:listener config-ref="HTTP_Listener_Configuration"
                path="run" doc:name="HTTP" />
            <sfdc:query config-ref="salesforce-oauth" accessTokenId="#[flowVars.OAuthAccessTokenId]"
                doc:name="Perform a query at Salesforce" query="SELECT id,lastname,lastmodifieddate from contact limit 10" />
            <foreach doc:name="For Each">
                <logger doc:name="Logger" level="INFO" message="contact: #[payload]" />
            </foreach>
            <set-payload doc:name="Set Payload to formatted output"
                value="Salesforce query returned #[payload.size()] contacts." />
            <logger doc:name="Logger" level="INFO" message="contact: #[payload]" />
        </flow>
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?为什么Salesforce不验证并返回访问令牌?我该如何使用回调网址?

小智 0

您需要使用 Salesforce 连接器,这非常简单。考虑到您当前尝试的方法,没有用户名,但提供了密码。

如果您使用下面的代码(从帖子中复制)-

  1. 访问令牌 URL - 这是正确的(我假设您直接访问产品)。
  2. 消费者密钥 - 这是正确的。
  3. 消费者秘密——正确
  4. 用户名 - 不存在
  5. 密码 - 不存在。当您尝试使用密码时,请确保附加安全性 toekn(如果启用)
  <sfdc:config-with-oauth name="salesforce-oauth"
            onNoToken="EXCEPTION"
       accessTokenUrl="https://app.my.salesforce.com/services/oauth2/token"

     authorizationUrl="https://app.my.salesforce.com/services/oauth2/authorize"
            consumerKey="myConsumerKey"
            consumerSecret="33388E8E" doc:name="Salesforce (OAuth)">
            <sfdc:oauth-callback-config domain="localhost"
                localPort="8081" remotePort="8081" path="AppCallBack" />
        </sfdc:config-with-oauth>
Run Code Online (Sandbox Code Playgroud)