コード例 #1
0
 /**
  * {@inheritDoc}
  */
 public function forget()
 {
     $code = $this->check();
     if ($code === null) {
         return;
     }
     $this->session->forget();
     $this->cookie->forget();
     return $this->remove($code);
 }
コード例 #2
0
ファイル: ManagerTest.php プロジェクト: sohailaammarocs/lfc
 /** @test */
 public function authenticate_with_oauth1_with_unlinked_non_existent_user()
 {
     $manager = $this->mockManager('make');
     $user = m::mock('Cartalyst\\Sentinel\\Users\\UserInterface');
     $manager->shouldReceive('make')->with('foo', 'http://example.com/callback')->once()->andReturn($provider = m::mock('League\\OAuth1\\Client\\Server\\Server'));
     // Request proxy
     $this->requestProvider->shouldReceive('getOAuth1TemporaryCredentialsIdentifier')->once()->andReturn('identifier');
     $this->requestProvider->shouldReceive('getOAuth1Verifier')->once()->andReturn('verifier');
     // Mock retrieving credentials from the underlying package
     $this->session->shouldReceive('get')->andReturn($temporaryCredentials = m::mock('League\\OAuth1\\Client\\Credentials\\TemporaryCredentials'));
     $provider->shouldReceive('getTokenCredentials')->with($temporaryCredentials, 'identifier', 'verifier')->once()->andReturn($tokenCredentials = m::mock('League\\OAuth1\\Client\\Credentials\\TokenCredentials'));
     // Unique ID
     $provider->shouldReceive('getUserUid')->once()->andReturn(789);
     // Finding an appropriate link
     $this->linkRepository->shouldReceive('findLink')->with('foo', 789)->once()->andReturn($link = m::mock('Cartalyst\\Sentinel\\Addons\\Social\\Models\\LinkInterface'));
     $link->shouldReceive('storeToken')->with($tokenCredentials)->once();
     $this->sentinel->shouldReceive('getUser')->once();
     $link->shouldReceive('getUser')->once();
     $link->shouldReceive('getUser')->once()->andReturn($user);
     $link->shouldReceive('setUser')->with($user)->once();
     $provider->shouldReceive('getUserEmail')->once()->andReturn('*****@*****.**');
     $this->sentinel->shouldReceive('findByCredentials')->with(['login' => '*****@*****.**'])->once();
     $this->sentinel->shouldReceive('getUserRepository')->once()->andReturn($users = m::mock('Cartalyst\\Sentinel\\Users\\UserRepositoryInterface'));
     $users->shouldReceive('createModel')->once()->andReturn($user);
     $provider->shouldReceive('getUserScreenName')->once()->andReturn(['Ben', 'Corlett']);
     $this->sentinel->shouldReceive('registerAndActivate')->once()->andReturn($user);
     $this->sentinel->shouldReceive('authenticate')->with($user, true)->once()->andReturn($user);
     $manager->registering(function ($link, $provider, $token, $slug) {
         $_SERVER['__sentinel_social_registering'] = true;
     });
     $manager->registered(function ($link, $provider, $token, $slug) {
         $_SERVER['__sentinel_social_registered'] = true;
     });
     $user = $manager->authenticate('foo', 'http://example.com/callback', function () {
         $_SERVER['__sentinel_social_linking'] = func_get_args();
     }, true);
     $this->assertTrue(isset($_SERVER['__sentinel_social_registering']));
     $this->assertTrue(isset($_SERVER['__sentinel_social_registered']));
     $this->assertTrue(isset($_SERVER['__sentinel_social_linking']));
     $eventArgs = $_SERVER['__sentinel_social_linking'];
     unset($_SERVER['__sentinel_social_registering']);
     unset($_SERVER['__sentinel_social_registered']);
     unset($_SERVER['__sentinel_social_linking']);
     $this->assertCount(4, $eventArgs);
     list($_link, $_provider, $_tokenCredentials, $_slug) = $eventArgs;
     $this->assertEquals($link, $_link);
     $this->assertEquals($provider, $_provider);
     $this->assertEquals($tokenCredentials, $_tokenCredentials);
     $this->assertEquals('foo', $_slug);
 }
コード例 #3
0
ファイル: Manager.php プロジェクト: sohailaammarocs/lfc
 /**
  * Retrieves a token (OAuth1 token credentials or OAuth2 access
  * token) for the given provider, abstracting away the
  * differences from the user.
  *
  * @param  mixed  $provider
  * @return mixed
  * @throws \Cartalyst\Sentinel\Addons\Social\AccessMissingException
  */
 protected function retrieveToken($provider)
 {
     if ($this->oauthVersion($provider) == 1) {
         $temporaryIdentifier = $this->request->getOAuth1TemporaryCredentialsIdentifier();
         if (!$temporaryIdentifier) {
             throw new AccessMissingException('Missing [oauth_token] parameter (used for OAuth1 temporary credentials identifier).');
         }
         $verifier = $this->request->getOAuth1Verifier();
         if (!$verifier) {
             throw new AccessMissingException('Missing [verifier] parameter.');
         }
         $temporaryCredentials = $this->session->get();
         $tokenCredentials = $provider->getTokenCredentials($temporaryCredentials, $temporaryIdentifier, $verifier);
         return $tokenCredentials;
     }
     $code = $this->request->getOAuth2Code();
     if (!$code) {
         throw new AccessMissingException("Missing [code] parameter.");
     }
     $accessToken = $provider->getAccessToken('authorization_code', compact('code'));
     return $accessToken;
 }