【问题标题】:Linkedin API oAuth 2.0 REST Query parametersLinkedin API oAuth 2.0 REST 查询参数
【发布时间】:2014-09-14 18:43:13
【问题描述】:

我在向回调 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,我可以正常授权并接收令牌。如果我可以在回调 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 中成功传递额外查询参数的经验?如果是这样,我做错了什么?

【问题讨论】:

    标签: rest oauth-2.0 linkedin


    【解决方案1】:

    我等不及领英代表的回复了。在 much 实验之后,我只能推测不允许在回调中使用额外的查询参数(感谢让我的应用程序更复杂)。正如问题 #25 中所建议的那样,我已将我需要的东西隐藏在请求的“state=”参数中,以便将其返回到我的回调中。

    在我的情况下,我正在处理来自我的回调的多个 API 和来自多个用户的请求,因此我需要知道类型和用户编号。作为一种解决方案,我将随机字符串附加到前缀,以便我可以在回调中提取查询参数并进行处理。因此,每个 state= 都是唯一的,并为我提供了一个唯一的键来缓存/从缓存中获取对象.. 所以 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)
    }
    

    【讨论】:

    • 非常感谢!使用状态参数 a 把所有需要的数据放在那里是一个很好的技巧
    【解决方案2】:

    你不允许这样做。 参考文档:https://developer.linkedin.com/docs/oauth2

    请注意:

    我们强烈建议尽可能使用 HTTPS URL 必须是绝对的(例如“https://example.com/auth/callback”,而不是“/auth/callback”) URL 参数被忽略(即https://example.com/?id=1https://example.com/ 相同) 网址不能包含#(即“https://example.com/auth/callback#linkedin”无效)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-19
      • 2020-10-14
      • 1970-01-01
      • 2019-09-08
      • 2013-07-08
      • 2014-03-30
      • 2017-11-22
      相关资源
      最近更新 更多