New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoupled access token handling #129

Merged
merged 1 commit into from Jun 25, 2014

Conversation

Projects
None yet
3 participants
@SammyK
Collaborator

SammyK commented Jun 24, 2014

This continues #95 but will be improved with #36 and #103.

Access tokens have been decoupled from FacebookSession! Yay. Now we can handle access tokens directly.

use Facebook\Entities\AccessToken;

$accessToken = new AccessToken('my_short_lived_token');

// AccessToken object can be echo'ed as a string
echo $accessToken; // my_short_lived_token

// And exchanged for a long lived token
$longLivedToken = $accessToken->extend();

// . . .

// Obtain a code for this long lived token
$code = AccessToken::getCodeFromAccessToken($longLivedToken);
// Obtain a short-lived token for use on clients
$shortLivedAccessTokenForClients = AccessToken::getAccessTokenFromCode($code);

And you can grab it from FacebookSession and play with it.

use Facebook\FacebookRedirectLoginHelper;

$helper = new FacebookRedirectLoginHelper($redirect_url);
$session = $helper->getSessionFromRedirect();

$accessToken = $session->getAccessToken();

if ($accessToken->isLongLived()) {
  // This is a long lived access token.
  // That means you can get a code with it.
  // Or store it in the database and use later.
}

if ($accessToken->expiresAt()) {
  echo 'Your token expires at ' . $accessToken->expiresAt()->format('Y-m-d H:i:s');
} else {
  echo 'Your token never expires!';
}

FacebookSession::getToken() works the same as it always has (returns a string of the access token).

Now, there is still a lot of work to do on this. There are still some pretty deep method calling as well a too much direct access to Graph in the tests, but it's def a good step in the right direction! :)

@SammyK

This comment has been minimized.

Show comment
Hide comment
@SammyK

SammyK Jun 25, 2014

Collaborator

Thanks for the code review as always @yguedidi! I'll get cracking on these a bit later today. :)

Collaborator

SammyK commented Jun 25, 2014

Thanks for the code review as always @yguedidi! I'll get cracking on these a bit later today. :)

@SammyK

This comment has been minimized.

Show comment
Hide comment
@SammyK

SammyK Jun 25, 2014

Collaborator

Done!

Collaborator

SammyK commented Jun 25, 2014

Done!

gfosco added a commit that referenced this pull request Jun 25, 2014

@gfosco gfosco merged commit ceb0e69 into facebook:master Jun 25, 2014

@SammyK

This comment has been minimized.

Show comment
Hide comment
@SammyK

SammyK Jun 25, 2014

Collaborator

👍 And now to start tackling #36... Phew! :)

Collaborator

SammyK commented Jun 25, 2014

👍 And now to start tackling #36... Phew! :)

@SammyK SammyK deleted the SammyK:decouple-access-token-handling branch Jun 25, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment