LinkedIn API OAuth 刷新令牌



我正在使用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 请求并必须弹出登录屏幕吗?如何避免?将不胜感激的建议。

谢谢。

发现了。授权网址:

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

后跟访问令牌 URL:

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

是我真正要做的一切(使用正确的参数传递(。

还有一个端点可以在令牌过期后刷新令牌,以下是执行此操作方法的文档: https://learn.microsoft.com/en-us/linkedin/shared/authentication/programmatic-refresh-tokens

如果您浏览文档

LinkedIn不提供刷新令牌,则需要再次执行工作流。

以下是简短的解释:

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

刷新访问令牌

最新更新