/** * Request access token from GitHub and return a LoginRequest object for logging into our app * * @param Oauth2Service\GitHub $github * @param TokenInterface $token * @return LoginRequest */ protected function github(Oauth2Service\GitHub $github, TokenInterface $token) { $emails = json_decode($github->request('user/emails'), true); $user = json_decode($github->request('user'), true); $loginRequest = new LoginRequest('github', $user['id'], $token->getAccessToken(), $token->getEndOfLife() > 0 ? $token->getEndOfLife() : 0, $token->getRefreshToken(), $emails); return $loginRequest; }
/** * @covers OAuth\OAuth2\Service\GitHub::__construct * @covers OAuth\OAuth2\Service\GitHub::getExtraApiHeaders */ public function testGetExtraApiHeaders() { $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(2)); $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); $service = new GitHub($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), $client, $storage); $headers = $service->request('https://pieterhordijk.com/my/awesome/path'); $this->assertTrue(array_key_exists('Accept', $headers)); $this->assertSame('application/vnd.github.beta+json', $headers['Accept']); }
/** * @covers OAuth\OAuth2\Service\GitHub::__construct * @covers OAuth\OAuth2\Service\GitHub::getAccessTokenEndpoint */ public function testGetAccessTokenEndpoint() { $service = new GitHub($this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), $this->getMock('\\Buzz\\Browser'), $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')); $this->assertSame('https://github.com/login/oauth/access_token', (string) $service->getAccessTokenEndpoint()); }