Skip to content

Instantly share code, notes, and snippets.

@ovr
Created August 15, 2017 15:22
Show Gist options
  • Save ovr/b3ecb840ce5a3774d69ce5e0d637f121 to your computer and use it in GitHub Desktop.
Save ovr/b3ecb840ce5a3774d69ce5e0d637f121 to your computer and use it in GitHub Desktop.
<?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