PHP-OAuth2
PHP-OAuth2 copied to clipboard
How to use the refresh token
I have made the setup for php-oauth2 with wordpress. But it get expires after some days. I want to stay it permanent or use the refresh token to renew the token automatically using php code. Please can you help me.
Please can anyone help me.
I know this is SUPER late, but just in case you still need it, or someone else comes along:
'refresh_toke' grant type is done via the same getAccessToken function, you just pass 'refresh_token' and the access token URL to it.
Code Sample:
require("Client.php");
require("GrantType/IGrantType.php");
require("GrantType/AuthorizationCode.php");
require("GrantType/RefreshToken.php");
$authorizeUrl = '';
$accessTokenUrl = '';
$clientId = '';
$clientSecret = '';
if (isset($_SESSION['access_token']))
{
$LoggedIn = TRUE;
$params = array("refresh_token" => $_SESSION['refresh_token']);
$client = new OAuth2\Client($clientId, $clientSecret, OAuth2\Client::AUTH_TYPE_AUTHORIZATION_BASIC);
$client->setCurlOption(CURLOPT_USERAGENT,$userAgent);
$response = $client->getAccessToken($accessTokenUrl, 'refresh_token', $params);
print_r($response);
$client->setAccessToken($response["result"]["access_token"]);
$_SESSION['access_token'] = $response["result"]["access_token"];
$client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_BEARER);
}
What code would the RefreshToken.php
contain in this example?
I know this is SUPER late, but just in case you still need it, or someone else comes along:
'refresh_toke' grant type is done via the same getAccessToken function, you just pass 'refresh_token' and the access token URL to it.
More than 6 years after this post, I would like to say a big thank you for this. I think I would not have made my authentification script working without this help. Hope the original poster will see this message :)