【问题标题】:LinkedIn API OAuth refresh tokenLinkedIn API OAuth 刷新令牌
【发布时间】:2017-12-20 13:03:05
【问题描述】:

我正在使用 LinkedIn API 从那里提取更新并显示在网站上。在使用 OAuth 时,我将令牌存储在一个文件中,然后再次从那里拉出它以防止登录弹出窗口。但是,我不清楚令牌过期后将如何刷新。以下是我从文件中读取令牌的方式-

        $config = json_decode(file_get_contents(".service.dat"));
        if( isset($config->key) && isset($config->secret) ) {
            $this->access_token = new OAuthConsumer($config->key, $config->secret);
        } 

对于身份验证,我有以下获取请求令牌 -

function getRequestToken()
{
    $consumer = $this->consumer;
    $request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $this->request_token_path);
    $request->set_parameter("oauth_callback", $this->oauth_callback);
    $request->sign_request($this->signature_method, $consumer, NULL);
    $headers = Array();
    $url = $request->to_url();
    $response = $this->httpRequest($url, $headers, "GET");
    parse_str($response, $response_params);
    $this->request_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
}

生成令牌后,我正在生成授权网址:

function generateAuthorizeUrl()
{
    $consumer = $this->consumer;
    $request_token = $this->request_token;
    return $this->authorize_path . "?oauth_token=" . $request_token->key;
}

LinkedIn 文档说明以下有关刷新令牌:

刷新访问令牌非常简单,无需 为用户显示授权对话框。换句话说,它是一个 不会影响您的应用程序用户的无缝流程 经验。只需让您的应用程序通过授权 流以获取一个额外的 60 天的新访问令牌 寿命。

我不清楚这意味着什么。如果我必须从再次获取请求令牌一直重做,那是否不需要我再次发出 http 请求并且必须弹出登录屏幕?我该如何避免呢?将不胜感激。

谢谢。

【问题讨论】:

    标签: php oauth linkedin-api


    【解决方案1】:

    发现了。授权网址:

    https://www.linkedin.com/oauth/v2/authorization

    后跟访问令牌网址:

    https://www.linkedin.com/oauth/v2/accessToken

    这就是我真正需要做的一切(传递正确的参数)。

    【讨论】:

      【解决方案2】:

      如果你仔细阅读文档

      Linkedin 不提供您需要再次完成工作流程的刷新令牌。

      这里是简短的解释:

      要刷新访问令牌,只需再次执行本文档中概述的授权过程以获取新令牌。在刷新工作流期间,如果满足以下条件,流程的授权对话部分会自动跳过,用户会被重定向回您的回调 URL,从而使获取刷新的访问令牌成为无缝的幕后用户体验

      Refresh your Access Tokens

      【讨论】:

      • 虽然答案可以包含参考链接,但答案本身至少应该包含基本解释。
      【解决方案3】:

      还有一个端点可以在令牌过期后刷新,这里是这样做的文档:https://docs.microsoft.com/en-us/linkedin/shared/authentication/programmatic-refresh-tokens

      【讨论】:

        猜你喜欢
        • 2014-08-19
        • 2013-11-23
        • 1970-01-01
        • 2016-01-19
        • 2020-05-05
        • 1970-01-01
        • 2017-11-20
        • 2015-02-25
        • 1970-01-01
        相关资源
        最近更新 更多