public function testOAuth1Header() { /** @var Client $client */ $client = new AuthorizedHttpClient(new OAuth1AccessToken(['consumer_key' => 'test_consumer_key', 'consumer_secret' => 'test_consumer_secret', 'token_value' => 'test_token_value', 'token_secret' => 'test_token_secret'])); $request = $client->createRequest('GET', 'http://baidu.com'); $client->getEmitter()->attach(new Mock([new Response(200, [], Stream::factory('some response'))])); $client->send($request); $this->assertStringStartsWith('OAuth', $request->getHeader('Authorization')); }
/** * @param AccessToken $token * @return StandardUser */ public function getUser(AccessToken $token) { /** @var \GuzzleHttp\Client $httpClient */ $httpClient = new AuthorizedHttpClient($token); /** @var Response $response */ $response = $httpClient->get('https://api.twitter.com/1.1/account/verify_credentials.json'); $rawUser = $response->json(); $user = new StandardUser(['version' => AccessTokenInterface::VERSION_OAUTH1, 'provider' => 'Twitter', 'id' => $rawUser['id'], 'name' => $rawUser['name'], 'avatar' => $rawUser['profile_image_url'], 'extra' => $rawUser]); return $user; }
/** * @param AccessToken $token * @return StandardUser */ public function getUser(AccessToken $token) { /** @var Client $httpClient */ $httpClient = new AuthorizedHttpClient($token); /** @var Response $response */ $response = $httpClient->get('https://api.douban.com/v2/user/~me'); $rawUser = $response->json(); $user = new StandardUser(['version' => AccessTokenInterface::VERSION_OAUTH2, 'provider' => 'Douban', 'id' => $rawUser['id'], 'name' => $rawUser['uid'], 'avatar' => $rawUser['avatar'], 'extra' => $rawUser]); return $user; }