Salesforce REST API 回调 URL 是否需要为 HTTPS?

发布于 2024-12-03 17:01:27 字数 650 浏览 0 评论 0原文

我一直在尝试连接到 Salesforce REST API,但运气不太好。 Salesforce REST API 快速入门指南 指出需要 HTTPS 回调 url,但在他们使用的示例中https://localhost:8443/RestTest/oauth/_callback 作为回调 URL。

我尝试使用此 php Salesforce REST API 示例,但 Salesforce 似乎已经适应并进入了重定向循环。

如果我没有 SSL 证书,是否可以连接到 Salesforce REST API?如果可以,我该如何操作?根据记录,我的应用程序是用 PHP 编写的,而不是像大多数官方示例那样用 Java 编写。

I have been trying to connect to the Salesforce REST API but am not having very much luck.
The Salesforce REST API Quick Start Guide states that an HTTPS callback url is required, but then in the example they use https://localhost:8443/RestTest/oauth/_callback as the callback url.

I tried connecting on my testing server (HTTP) using this php Salesforce REST API example, but Salesforce seems to have had a fit and entered a redirect loop.

Is it possible to connect to the Salesforce REST API if I do not have an SSL Certificate, and if so, how might I go about doing so? For the record, my application is written in PHP, not Java like most of the official examples are.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老街孤人 2024-12-10 17:01:27

对于 localhost,它接受 http,除了 localhost 之外,您应该使用 https。
但请求中的重定向 URI 和连接的应用程序中的回调 url 应匹配。

您可以在连接的应用程序和请求中使用 http://localhost:8080/

For localhost it accepts http, and you should use https for other than localhost.
But the redirect URI in the request and the callback url in the connected app should get matched.

You can use http://localhost:8080/<any_page_in_ur_project> in both connected app and in request.

小巷里的女流氓 2024-12-10 17:01:27

我从未使用过 Salesforce REST API,但我已阅读您链接到的页面。

OAuth 回调 URL 必须是 HTTPS。您似乎自己在文档中发现了这一点:

它必须是安全的:http:// 不起作用,只能使用 https://

...以及示例:

@WebInitParam(name = "redirectUri", value = 
    "https://localhost:8443/RestTest/oauth/_callback")

至于您的其他问题:

如果我没有 SSL 证书,是否可以连接到 Salesforce REST API?如果可以,我该如何操作?

大概是通过第二种方法,正如您链接到的页面第一句话中提到的:

您可以使用 OAuth 2.0 或通过传递会话 ID 来设置授权。

...

会话 ID 授权

如果您不处理其他人的密码,则可以使用会话 ID 代替 OAuth 2.0 访问令牌:

  1. 获取会话 ID,例如,SOAP Web 服务 API login() 调用会返回会话 ID。您还可能拥有会话 ID,例如作为 Apex 当前上下文的一部分。

  2. 向资源发送请求时使用会话 ID。将 ID 替换为令牌值。

因此,只要您不处理其他人的密码(无论这意味着什么),您就可以使用 login() 获取会话 ID 并从那里与 Web 服务进行通信。

I've never used the Salesforce REST API, but I have read the page you linked to.

The OAuth callback URL must be HTTPS. You seem to have discovered this yourself, both in the documentation:

It must be secure: http:// does not work, only https://

...and the example:

@WebInitParam(name = "redirectUri", value = 
    "https://localhost:8443/RestTest/oauth/_callback")

As for your other question:

Is it possible to connect to the Salesforce REST API if I do not have an SSL Certificate, and if so, how might I go about doing so?

Presumably by the second method, as alluded to in the first sentence on the page you linked to:

You can set up authorization using OAuth 2.0 or by passing a session ID.

...

Session ID Authorization

You can use a session ID instead of an OAuth 2.0 access token if you aren't handling someone else's password:

  1. Obtain a session ID, for example, a SOAP Web services API login() call returns the session ID. You may also have the session ID, for example as part of the Apex current context.

  2. Use the session ID when you send a request to the resource. Substitute the ID for the token value.

So provided you aren't handling some else's password (whatever that means), you can use login() to get a Session ID and communicate with the web service from there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文