【问题标题】:Can LinkedIn's access token renewal flow be performed on the server?LinkedIn的访问令牌更新流程可以在服务器上执行吗?
【发布时间】:2013-12-27 09:36:04
【问题描述】:

在 Facebook 的 Graph API 中,一旦我们对用户进行了初始身份验证,我们就可以直接与 API(从服务器)进行交互,以获取长期存在的页面访问令牌。这个长期存在的页面访问令牌永不过期。 (https://developers.facebook.com/docs/facebook-login/access-tokens/)

在阅读 LinkedIn 的文档时,似乎不可能获得具有无限期(未过期)访问令牌的访问令牌。它们似乎每 60 天到期一次。但是,这些访问令牌可以在 60 天到期之前刷新。

文档中不完全清楚的是,是否可以在没有客户端交互的情况下单独在服务器上执行访问令牌更新。文档的语言表明需要客户端(浏览器)的交互,但没有明确说明。

所以,我的问题是,是否可以单独使用服务器更新 LinkedIn 访问令牌,而无需客户端(浏览器)的交互?

相关LinkedIn参考资料:https://developer.linkedin.com/documents/handling-errors-invalid-tokens

【问题讨论】:

    标签: api oauth oauth-2.0 linkedin


    【解决方案1】:

    我有同样的问题,LinkedIn 文档和论坛帖子令人困惑,但我现在很确定,如果没有用户干预,不可能以编程方式进行(即用户需要通过 LinkedIn auth 登录到您的应用程序才能刷新令牌)。

    【讨论】:

    • 这就是我所担心的...您是否实施了任何措施来帮助使重新身份验证过程更顺畅/对用户来说不那么不方便?我很想了解更多关于您的工作流程的信息!
    • 即使我也在寻找相同的东西,但我认为没有用户干预就无法刷新 oauth2 linkedin 令牌。我开始知道可以通过这种方式刷新 Facebook 令牌,但不幸的是,似乎用linkedin 是不可能的。
    【解决方案2】:

    事实证明,如果没有linkedin 用户登录到linkedin,就无法刷新linkedin 的访问令牌。请参考LinkedIn员工的第一条评论here,其中明确指出"this refresh will only work if the user is still logged into LinkedIn (authenticated) and the current access token isn't expired. Otherwise, the user will be presented with the login dialog again."

    我想这对于以前将linkedin访问令牌存储到数据库以供以后使用的人来说是一个主要问题。

    我在这里提到的几个链接是指刷新linkedin oauth2令牌的问题(希望这能让每个遇到同样问题的人都清楚):

    1) This refresh will only work if the user is still logged into LinkedIn (authenticated) and the current access token isn't expired. Otherwise, the user will be presented with the login dialog again.

    2) There is no way to refresh the token using the old authentication token/secret. User needs to log into linkedin in order for you to refresh the tokens. We use this flow as it protects our members and their data in the best possible manner.

    3) Refreshing an access token is very simple and can happen without an authorization dialog appearing for the user. In other words, it's a seamless process that doesn't affect your application's user experience. Simply have your application go through the authorization flow in order to fetch a new access token with an additional 60 day life span. When the following conditions exist: -User is still logged into Linkedin.com -The current access token isn't expired (within the 60 life span) We will automatically redirect the user back to your redirect_uri without requiring them to reauthorize your application. If they don't exist, we'll prompt them to login and then redirect them.

    4) We have also standardized the duration of the authorization tokens. Previously, members could choose to grant tokens that were as short as one day or as long as forever. Now all tokens are 60 days in length, with the ability for you to extend them in a series of rolling 60 day increments whenever the member comes back to your application. To prevent a bad user experience in your application, be sure to proactively refresh tokens and elegantly route any expired tokens through a refresh flow.

    5) As long as the user is logged into LinkedIn and their current access token hasn't expired, you can fetch an access token with a 60 day lifespan the next time the user comes to your application.

    【讨论】:

    • 感谢您的回答!您会注意到,您发现的语句仍然有点模棱两可 - 例如,它可以解释为,只要用户仍然有一个活动会话 somewhere,您的后端代码可以独立连接以刷新令牌,而无需客户端的 cookie 等。对于它的价值,我得出的结论是客户端确实必须是令牌更新过程的一部分。事实上,不幸的是,如果不是这样,我会感到非常惊讶。
    • @rinogo,是的,你是对的。用户必须是令牌更新过程的一部分,因此仅从服务器端无法实现。
    • 大部分链接都失效了
    • 我发现这种方法非常令人失望,因为我唯一想做的就是检索 Wordpress 小部件的关注者数量。如果Linkedin目前提供了一个插件脚本,可以让你嵌入一个带有多个关注者的关注按钮,而无需所有的授权麻烦,也不需要用户交互,为什么我们自己做同样的事情要能够个性化那个该死的东西这么复杂?丑陋的按钮?我什至尝试过使用 MutationObservers 并从前端对其进行个性化设置的方法,但是那个该死的丑陋按钮在 3 个 iFrame 后面……太荒谬了!
    猜你喜欢
    • 2015-10-23
    • 1970-01-01
    • 2013-07-24
    • 1970-01-01
    • 2017-02-11
    • 2012-05-25
    • 2020-01-09
    • 2021-04-24
    • 1970-01-01
    相关资源
    最近更新 更多