Last active
October 13, 2015 14:02
-
-
Save YOzaz/7af39d1adbcbd5ff7c55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* ... */ | |
/** | |
* Gets Facebook login URL | |
* | |
* @param array $scope | |
* @return string | |
**/ | |
public function getLoginUrl( $scope = [] ) | |
{ | |
$redirect_url = $this->createLoginResultUrl(); | |
$helper = $this->fb->getRedirectLoginHelper(); | |
return $helper->getLoginUrl( $redirect_url, $scope ); | |
} | |
/** | |
* Creates resolving URL for Facebook login redirects | |
* | |
* @return string | |
**/ | |
protected function createLoginResultUrl() | |
{ | |
return url('api/facebook-token') . '/result'; | |
} | |
/** | |
* Parses Facebook redirect and returns access token | |
* | |
* @return string|null | |
**/ | |
public function parseLoginResult() | |
{ | |
$redirect_url = $this->createLoginResultUrl(); | |
$helper = $this->fb->getRedirectLoginHelper(); | |
if ( ! $accessToken = $helper->getAccessToken( $redirect_url ) ) | |
{ | |
return null; | |
} | |
$oAuth2Client = $this->fb->getOAuth2Client(); | |
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken( $accessToken ); | |
return is_string($longLivedAccessToken) ? (string)$longLivedAccessToken : $longLivedAccessToken->getValue(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment