如何使用服务器端身份验证在其他页面上使用新的访问令牌 - PODIO API

马尔Z15199

我已经使用GET['code']方法在 1 个 php 页面上对我的应用程序进行了身份验证,并且我收到了刷新令牌代码并保存了它。

现在我想在同一个域的其他页面上进行身份验证。所以我所做的是我创建了其他 php 页面,检查我是否已通过身份验证或未使用is_authenticated()函数,如果没有,我使用 CURL 请求新的访问令牌到 API 端点"https://podio.com/oauth/token"我收到了访问代码并尝试使用它进行身份验证,authenticate_with_authorization_code($code, REDIRECT_URI)但出现错误Uncaught PodioInvalidGrantError:“抱歉,您的 OAuth 代码无效。” . 请让我知道我错过了哪一步。

<?php
require ('podio/podio_lib/PodioAPI.php');
include ('sessionpodio.php');
define("REDIRECT_URI", 'http://domainname.com/pagename.php');

$refreshtoken = "my_refresh_token";
$client_id = "xxxxx";
$client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$param = "grant_type=refresh_token&client_id={$client_id}&client_secret= 
{$client_secret}&refresh_token={$refreshtoken}";
Podio::setup($client_id, $client_secret, array(
  "session_manager" => "PodioBrowserSession"
));


if (!Podio::is_authenticated()) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://podio.com/oauth/token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www- 
form-urlencoded'));

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);

$decoded_r = json_decode($server_output,true);
$code = $decoded_r["access_token"];


echo "<pre>".print_r($decoded_r, true)."</pre><br/>";
var_dump($code);

if ($code !== "") {
Podio::authenticate_with_authorization_code($code, REDIRECT_URI);   
}   
}

 elseif (Podio::is_authenticated()) {

  // User already has an active session. You can make API calls here:
    print "You were already authenticated and no authentication is needed. 
<br/>";
    var_dump($_SESSION);
}

?>  
马尔Z15199

使用跑道会话管理器解决了问题,不需要使用过期的访问令牌和刷新令牌的手动身份验证,因为库将自动处理它,有关更多信息,请参阅跑道会话管理器。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章