PHP Classes

Access token retrieve

Recommend this page to a friend!

      PHP oAuth2 lightweight wrapper  >  All threads  >  Access token retrieve  >  (Un) Subscribe thread alerts  
Subject:Access token retrieve
Summary:How can access the access token out of the library
Messages:1
Author:Stavros Zavrakas
Date:2014-07-01 11:23:56
 

  1. Access token retrieve   Reply   Report abuse  
Picture of Stavros Zavrakas Stavros Zavrakas - 2014-07-01 11:23:56
Hi,

I start using your library and it was quite easy to deploy together with laravel 4. I have a question, that possibly is a bug but I am not really sure and I would like to ask you about that. You have a public variable on the class that is named $accessToken. As I see in the module you never use it, or initialize. I suppose that this variable is used to have access to the access token out of the module. I modify a little bit the module initialize this variable in the Initialize function adding this line:
$this->accessToken = null; (line 78)

The second change that I did is in the public function getUserProfile() and assign back the acccess token to the class variable like that:
$this->accessToken = $atoken; (line 402)

I could do it in the function getAccessToken but I as I see you normalize the values for different social networks in the getUserProfile that's why I assign the accessToken there.

Like that I can have access to the accessToken that I need like that:
$oauth = new socialmedia_oauth_connect();

$oauth->provider="Google";

$oauth->client_id = "730362277469-tbeqm6l332n1al4pnfdgb83786a6g3f2.apps.googleusercontent.com";
$oauth->client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
$oauth->scope="https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me https://www.google.com/m8/feeds";
$oauth->redirect_uri ="http://ngiriraj.com/socialMedia/oauthlogin/google.php";

$oauth->Initialize();

$code = ($_REQUEST["code"]) ? ($_REQUEST["code"]) : "";

if(empty($code)) {
$oauth->Authorize();
}else{
$oauth->code = $code;
$getData = json_decode($oauth->getUserProfile());
$oauth->debugJson($getData);

// line that makes the difference
doSomethingWithAccessToken($oauth->accessToken);
/* redirect here */
}

Can you tell me if I am wrong in the concept? Is it possible to add this change to your module?