rest - Linkedin API oAuth 2.0 REST 查询参数

标签 rest oauth-2.0 linkedin

我在向回调 URL 添加查询时遇到了问题。我在尝试授权以下字符串时收到无效的 URI 方案错误:

https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=75df1ocpxohk88&scope=rw_groups%20w_messages%20r_basicprofile%20r_contactinfo%20r_network&state=7a6c697d357e4921aeb1ba3793d7af5a&redirect_uri=http://marktest.clubexpress.com/basic_modules/club_admin/website/auth_callback.aspx?type=linkedin

我在此处的论坛帖子中阅读了一些相互矛盾的信息。有人说可以将查询字符串添加到回调中,而其他人则说这会导致错误。

如果我删除 ?type=linkedin,我可以很好地授权并接收 token 。如果我可以在回调 url 上使用查询字符串,那将使我的生活变得更加轻松,因为我需要在回调中进行一些额外的处理。

简而言之,我可以在回调 url 的末尾附加一个查询字符串吗?

为了好玩,我尝试在请求中编码回调 url(根据他们的文档,显然这是一个禁忌): https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=75df1ocpxohk88&scope=rw_groups%20w_messages%20r_basicprofile%20r_contactinfo%20r_network&state=5cabef71d89149d48df523558bd12121&redirect_uri=http%3a%2f%2fmarktest.clubexpress.com%2fbasic_modules%2fclub_admin%2fwebsite%2fauth_callback.aspx%3ftype%3dlinkedin

这也会导致错误,但值得一试。

这里的文档:https://developer.linkedin.com/forum/oauth-20-redirect-url-faq-invalid-redirecturi-error表示您可以使用查询参数。在第一个请求中,我似乎做对了。在本页发布 #25 - https://developer.linkedin.com/forum/error-while-getting-access-token表示您必须删除查询参数才能使其工作

有没有人有使用 oAuth2.0 在 linkedin API 的回调 url 中成功传递额外查询参数的经验?如果是这样,我做错了什么?

最佳答案

我等不及 Linkedin 代表的回应了。经过多次 实验,我只能推测在回调中使用额外的查询参数是不允许的(感谢让我的应用程序变得更复杂)。正如问题的第 25 篇帖子中所建议的那样,我已经将我需要的东西隐藏在请求的“state=”参数中,以便它返回到我的回调。

在我的情况下,我正在处理来自多个用户的回调和请求的多个 API,因此我需要知道类型和用户编号。作为一种解决方案,我将一个随机字符串附加到一个前缀,这样我就可以在我的回调中提取查询参数并对其进行处理。因此,每个 state= 都是唯一的,并为我提供了一个唯一的 key 来缓存/从缓存中获取对象。 所以 state="Linkedin-5hnx5322d3-543"

所以,在我的回调页面上(对于你的 c# 人)

_stateString=Request["state"];
_receivedUserId = _stateString.Split('-')[2];
_receivedCacheKeyPrefix = _stateString.Split('-')[0];

if(_receivedCacheKeyPrefix == "Linkedin") {
     getUserDomain(_receivedUserId);
     oLinkedIn.AccessTOkenGet(Request["code"],_userDomain);
     if (oLinkedin.Token.Length > 0) {
     _linkedinToken = oLinkedin.Token;
     //now cache token using the entire _statestring and user id (removed for brevity)
}

关于rest - Linkedin API oAuth 2.0 REST 查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24912899/

相关文章:

rest - 创建 REST 架构

java - 出现严重错误 : MessageBodyWriter not found for media type=application/xml,

symfony - 在 Symfony2 中使用 OAuth2 client_credentials 进行身份验证

Linkedin Oauth2 客户端凭据授予类型

linkedin - 通过 LinkedIn API 发布的帖子不会出现在用户的更新中

javascript - 速率限制注册 API

javascript - 如何在 pokeAPI 中获取有关神奇​​宝贝的详细信息

spring-boot - 我应该明确验证 Keycloak token 还是由 Keycloak 适配器完成?

IOS 9 Swift - 解析 Facebook 登录不打开 native Facebook 应用程序

android - 从 Android LinkedIn SDK 获取个人资料信息