我已经使用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);
}
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句