Ejemplo n.º 1
0
 /**
  * @test
  * @expectedException SocialNorm\Exceptions\InvalidAuthorizationCodeException
  */
 public function it_throws_if_the_state_cant_be_verified()
 {
     $session = M::mock('SocialNorm\\Session');
     $session->shouldReceive('get')->with('oauth.state')->andReturn('valid-state');
     $provider = new ProviderStub('http://example.com/authorize', M::mock('SocialNorm\\User'));
     $socialNorm = new SocialNorm(new ProviderRegistry(), $session, new Request(['state' => 'invalid-state']), new StateGenerator());
     $socialNorm->registerProvider('foo', $provider);
     $socialNorm->getUser('foo');
 }
 /** @test */
 public function it_works()
 {
     $authorizeUrl = 'http://example.com/authorize';
     $user = M::mock('SocialNorm\\User');
     $provider = new ProviderStub($authorizeUrl, $user);
     $session = new InMemorySession();
     // Simulate first request
     $socialNorm = new SocialNorm(new ProviderRegistry(), $session, new Request([]), new StateGenerator());
     $socialNorm->registerProvider('foo', $provider);
     $returnedUrl = $socialNorm->authorize('foo');
     $this->assertStringStartsWith($authorizeUrl, $returnedUrl);
     // Simulate second request
     $state = $this->parseStateFromUrl($returnedUrl);
     $socialNorm = new SocialNorm(new ProviderRegistry(), $session, new Request(['state' => $state]), new StateGenerator());
     $socialNorm->registerProvider('foo', $provider);
     $returnedUser = $socialNorm->getUser('foo');
     $this->assertEquals($user, $returnedUser);
 }