コード例 #1
0
 public function testUserData()
 {
     $postResponse = m::mock('Guzzle\\Http\\Message\\Response');
     $postResponse->shouldReceive('getBody')->times(1)->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&uid=1');
     $getResponse = m::mock('Guzzle\\Http\\Message\\Response');
     $getResponse->shouldReceive('getBody')->andReturn('{"id": 12345, "name": "mock_name", "username": "******", "first_name": "mock_first_name", "last_name": "mock_last_name", "email": "mock_email", "Location": "mock_home", "bio": "mock_description", "link": "mock_facebook_url"}');
     $getResponse->shouldReceive('getInfo')->andReturn(['url' => 'mock_image_url']);
     $client = m::mock('Guzzle\\Service\\Client');
     $client->shouldReceive('setBaseUrl')->times(5);
     $client->shouldReceive('post->send')->times(1)->andReturn($postResponse);
     $client->shouldReceive('get->send')->andReturn($getResponse);
     $this->provider->setHttpClient($client);
     $token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
     $user = $this->provider->getUserDetails($token);
     $this->assertEquals(12345, $this->provider->getUserUid($token));
     $this->assertEquals(['mock_first_name', 'mock_last_name'], $this->provider->getUserScreenName($token));
     $this->assertEquals('mock_email', $this->provider->getUserEmail($token));
     $this->assertEquals('mock_email', $user->email);
 }
コード例 #2
0
ファイル: Auth.php プロジェクト: sergeyklay/phanbook
 /**
  * It will return uid, token and information user to save database
  *
  * @return array
  */
 public function authorize()
 {
     $this->view->disable();
     $provider = new Facebook(['clientId' => $this->clientId, 'clientSecret' => $this->clientSecret, 'redirectUri' => $this->redirectUriAuthorize]);
     $code = $this->request->getQuery('code');
     $state = $this->request->getQuery('state');
     if (!isset($code)) {
         // If we don't have an authorization code then get one
         $authUrl = $provider->getAuthorizationUrl();
         $this->session->set('oauth2state', $provider->state);
         return $this->response->redirect($authUrl);
         // Check given state against previously stored one to mitigate CSRF attack
     } elseif (empty($state) || $state !== $this->session->get('oauth2state')) {
         $this->session->remove('oauth2state');
         exit('Invalid state');
     } else {
         // Try to get an access token (using the authorization code grant)
         $token = $provider->getAccessToken('authorization_code', ['code' => $code]);
         $uid = $provider->getUserUid($token);
         $userDetails = $provider->getUserDetails($token);
         return array($uid, $token, $userDetails);
     }
 }