Created
August 15, 2017 15:22
-
-
Save ovr/b3ecb840ce5a3774d69ce5e0d637f121 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 | |
class OauthCbController extends AbstractController | |
{ | |
/** | |
* @Inject("SocialConnect\Auth\Service") | |
* | |
* @var \SocialConnect\Auth\Service | |
*/ | |
protected $oauth; | |
public function getAction() | |
{ | |
$id = $this->request->attributes->get('id'); | |
if ($id) { | |
throw new InvalidParameterException('id'); | |
} | |
$provider = $this->oauth->getProvider($id); | |
// Access token, access token is needed to perform API requests | |
$accessToken = $provider->getAccessTokenByRequestParameters($this->request->query->all()); | |
$externalUserId = $accessToken->getUserId(); | |
if ($externalUserId) { | |
// some APIs provide us user_id inside AccessToken, for example we can check in db that user have | |
// account and skip next step | |
return; | |
} | |
// We get user from social network | |
$user = $provider->getIdentity($accessToken); | |
// check in db that user register inside your site before, or register new account for him | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment