예제 #1
0
 public function testAll()
 {
     $identity = new Identity();
     $this->assertEquals([], $identity->all());
     $identity->set(Identity::PROPERTY_IMAGEURL, 'image-uri');
     $this->assertEquals(['image_url' => 'image-uri'], $identity->all());
     return $identity;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function getIdentity()
 {
     try {
         $data = $this->facebook->api('/me');
         $identity = new Identity();
         $identity->set(Identity::PROPERTY_ID, $data['id']);
         $identity->set(Identity::PROPERTY_IMAGEURL, sprintf('https://graph.facebook.com/%s/picture?return_ssl_resources=1', $data['username']));
         $identity->set(Identity::PROPERTY_EMAIL, $data['email']);
         $identity->set(Identity::PROPERTY_FIRSTNAME, $data['first_name']);
         $identity->set(Identity::PROPERTY_LASTNAME, $data['last_name']);
         $identity->set(Identity::PROPERTY_USERNAME, $data['username']);
     } catch (\FacebookApiException $e) {
         throw new NotAuthenticatedException('Unable to get profile informations', $e->getCode(), $e);
     }
     return $identity;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function getIdentity()
 {
     $identity = new Identity();
     try {
         $request = $this->client->get('https://api.github.com/user');
         $request->getQuery()->add('access_token', $this->session->get('github.provider.access_token'));
         $request->setHeader('Accept', 'application/json');
         $response = $request->send();
     } catch (GuzzleException $e) {
         throw new NotAuthenticatedException('Error while retrieving user info', $e->getCode(), $e);
     }
     if (200 !== $response->getStatusCode()) {
         throw new NotAuthenticatedException('Error while retrieving user info');
     }
     $data = @json_decode($response->getBody(true), true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw new NotAuthenticatedException('Error while parsing json');
     }
     list($firstname, $lastname) = explode(' ', $data['name'], 2);
     $identity->set(Identity::PROPERTY_EMAIL, $data['email']);
     $identity->set(Identity::PROPERTY_FIRSTNAME, $firstname);
     $identity->set(Identity::PROPERTY_ID, $data['id']);
     $identity->set(Identity::PROPERTY_IMAGEURL, $data['avatar_url']);
     $identity->set(Identity::PROPERTY_LASTNAME, $lastname);
     return $identity;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function getIdentity()
 {
     $identity = new Identity();
     try {
         $request = $this->client->get('https://api.linkedin.com/v1/people/~:(id,first-name,last-name,positions,industry,picture-url;secure=true,email-address)');
         $request->getQuery()->add('oauth2_access_token', $this->session->get('linkedin.provider.access_token'))->add('format', 'json');
         $response = $request->send();
     } catch (GuzzleException $e) {
         throw new NotAuthenticatedException('Unable to fetch LinkedIn identity', $e->getCode(), $e);
     }
     if (200 !== $response->getStatusCode()) {
         throw new NotAuthenticatedException('Error while retrieving user info');
     }
     $data = @json_decode($response->getBody(true), true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw new NotAuthenticatedException('Unable to parse Linkedin JSON identity');
     }
     if (0 < $data['positions']['_total']) {
         $position = array_pop($data['positions']['values']);
         $identity->set(Identity::PROPERTY_COMPANY, $position['company']['name']);
     }
     $identity->set(Identity::PROPERTY_EMAIL, $data['emailAddress']);
     $identity->set(Identity::PROPERTY_FIRSTNAME, $data['firstName']);
     $identity->set(Identity::PROPERTY_ID, $data['id']);
     $identity->set(Identity::PROPERTY_IMAGEURL, $data['pictureUrl']);
     $identity->set(Identity::PROPERTY_LASTNAME, $data['lastName']);
     return $identity;
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function getIdentity()
 {
     $identity = new Identity();
     $token = @json_decode($this->session->get('google-plus.provider.token'), true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw new NotAuthenticatedException('Unable to parse Google+ JSON');
     }
     try {
         $request = $this->guzzle->get(sprintf('https://www.googleapis.com/oauth2/v1/tokeninfo?%s', http_build_query(['access_token' => $token['access_token']], '', '&')));
         $response = $request->send();
     } catch (GuzzleException $e) {
         throw new NotAuthenticatedException('Unable to retrieve Google+ tokeninfo', $e->getCode(), $e);
     }
     if (200 !== $response->getStatusCode()) {
         throw new NotAuthenticatedException('Error while retrieving user info');
     }
     try {
         $plusData = $this->plus->people->get('me');
     } catch (\Google_Exception $e) {
         throw new NotAuthenticatedException('Error while retrieving user info', $e->getCode(), $e);
     }
     $data = @json_decode($response->getBody(true), true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw new NotAuthenticatedException('Unable to parse Google+ JSON');
     }
     $identity->set(Identity::PROPERTY_EMAIL, $data['email']);
     $identity->set(Identity::PROPERTY_FIRSTNAME, $plusData['name']['givenName']);
     $identity->set(Identity::PROPERTY_ID, $plusData['id']);
     $identity->set(Identity::PROPERTY_IMAGEURL, $plusData['image']['url']);
     $identity->set(Identity::PROPERTY_LASTNAME, $plusData['name']['familyName']);
     return $identity;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function getIdentity()
 {
     $identity = new Identity();
     try {
         $request = $this->client->get('https://api.viadeo.com/me?secure=true');
         $request->getQuery()->add('access_token', $this->session->get('viadeo.provider.access_token'));
         $request->setHeader('Accept', 'application/json');
         $response = $request->send();
     } catch (GuzzleException $e) {
         throw new NotAuthenticatedException('Unable to retrieve Viadeo identity');
     }
     if (200 !== $response->getStatusCode()) {
         throw new NotAuthenticatedException('Error while retrieving user info');
     }
     $data = @json_decode($response->getBody(true), true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw new NotAuthenticatedException('Unable to parse Viadeo identity.');
     }
     $identity->set(Identity::PROPERTY_FIRSTNAME, $data['first_name']);
     $identity->set(Identity::PROPERTY_ID, $data['id']);
     $identity->set(Identity::PROPERTY_IMAGEURL, $data['picture_large']);
     $identity->set(Identity::PROPERTY_LASTNAME, $data['last_name']);
     $identity->set(Identity::PROPERTY_USERNAME, $data['nickname']);
     try {
         $request = $this->client->get('https://api.viadeo.com/me/career?secure=true');
         $request->getQuery()->add('access_token', $this->session->get('viadeo.provider.access_token'));
         $request->setHeader('Accept', 'application/json');
         $response = $request->send();
     } catch (GuzzleException $e) {
         throw new NotAuthenticatedException('Unable to retrieve Viadeo career information.');
     }
     if (200 !== $response->getStatusCode()) {
         throw new NotAuthenticatedException('Error while retrieving company info');
     }
     $data = @json_decode($response->getBody(true), true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw new NotAuthenticatedException('Unable to parse Viadeo career informations.');
     }
     if (0 < count($data['data'])) {
         $job = array_shift($data['data']);
         $identity->set(Identity::PROPERTY_COMPANY, $job['company_name']);
     }
     return $identity;
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function getIdentity()
 {
     $access_token = $this->session->get('twitter.provider.access_token');
     $this->twitter->config['user_token'] = $access_token['oauth_token'];
     $this->twitter->config['user_secret'] = $access_token['oauth_token_secret'];
     $code = $this->twitter->request('GET', $this->twitter->url('1/account/verify_credentials'));
     if ($code != 200) {
         throw new NotAuthenticatedException('Unable to retrieve twitter identity');
     }
     $resp = @json_decode($this->twitter->response['response'], true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw new NotAuthenticatedException('Unable to parse Twitter Identity JSON response.');
     }
     $identity = new Identity();
     $identity->set(Identity::PROPERTY_USERNAME, $resp['screen_name']);
     $identity->set(Identity::PROPERTY_IMAGEURL, $resp['profile_image_url_https']);
     $identity->set(Identity::PROPERTY_ID, $resp['id']);
     return $identity;
 }