Esempio n. 1
0
 public function testGetAccessTokenRefreshTokenGrant()
 {
     $config = $this->getConfig();
     $oauth2Client = new OAuth2Client($config);
     $accessTokenExpectedResponse = new AccessTokenSuccessfulResponse(new AccessToken('2YotnFZFEjr1zCsicMWpAA'), TokenType::BEARER());
     $accessTokenExpectedResponse->setExpiresIn(new ExpiresIn(3600));
     $accessTokenExpectedResponse->setRefreshToken(new RefreshToken('dD3BGS4cfASc3CFS23caxcs'));
     $accessTokenRequest = new AccessTokenRequest(new RefreshToken('tGzv3JOkF0XG5Qx2TlKWIA'));
     $grant = new RefreshTokenGrant($accessTokenRequest);
     $accessTokenResponse = $oauth2Client->obtainAccessToken($grant);
     $this->assertEquals($accessTokenExpectedResponse, $accessTokenResponse);
 }
 /**
  * @param ResponseInterface $httpResponse
  * @return AccessTokenSuccessfulResponseInterface
  * @throws InvalidArgumentException
  */
 public function convertHttpResponseToAccessTokenSuccessfulResponse(ResponseInterface $httpResponse)
 {
     $body = $this->getHttpResponseDecoder()->decode($httpResponse);
     Assertion::keyExists($body, 'access_token', 'Access token param in body is required.');
     Assertion::keyExists($body, 'token_type', 'Token type param in body is required.');
     $accessTokenSuccessfulResponse = new AccessTokenSuccessfulResponse(new AccessToken($body['access_token']), new TokenType(ucfirst(strtolower($body['token_type']))));
     if (isset($body['expires_in'])) {
         $accessTokenSuccessfulResponse->setExpiresIn(new ExpiresIn($body['expires_in']));
     }
     if (isset($body['refresh_token'])) {
         $accessTokenSuccessfulResponse->setRefreshToken(new RefreshToken($body['refresh_token']));
     }
     if (isset($body['scope'])) {
         $accessTokenSuccessfulResponse->setScope(Scope::fromParameter($body['scope']));
     }
     return $accessTokenSuccessfulResponse;
 }
 public function testConvertHttpResponseToAccessTokenSuccessfulResponse()
 {
     $httpClientMock = $this->getHttpClientMock();
     $configMock = $this->getConfigMock();
     $decoderMock = $this->getResponseJsonDecoderMock();
     $accessTokenObtainTemplate = new DefaultAccessTokenObtainTemplate($httpClientMock, $configMock, $decoderMock);
     $httpResponseMock = $this->getMockBuilder('\\MostSignificantBit\\OAuth2\\Client\\Http\\ResponseInterface')->getMockForAbstractClass();
     $decoderMock->expects($this->once())->method('decode')->with($httpResponseMock)->willReturn(array('access_token' => '2YotnFZFEjr1zCsicMWpAA', 'token_type' => 'Bearer', 'expires_in' => 3600, 'refresh_token' => 'tGzv3JOkF0XG5Qx2TlKWIA', 'scope' => 'example1 example2', 'not_specified' => 'foo'));
     $expectedAccessTokenSuccessFullResponse = new SuccessfulResponse(new AccessToken('2YotnFZFEjr1zCsicMWpAA'), new TokenType('Bearer'));
     $expectedAccessTokenSuccessFullResponse->setRefreshToken(new RefreshToken('tGzv3JOkF0XG5Qx2TlKWIA'));
     $expectedAccessTokenSuccessFullResponse->setExpiresIn(new ExpiresIn(3600));
     $expectedAccessTokenSuccessFullResponse->setScope(new Scope(array('example1', 'example2')));
     $accessTokenSuccessFullResponse = $accessTokenObtainTemplate->convertHttpResponseToAccessTokenSuccessfulResponse($httpResponseMock);
     $this->assertEquals($expectedAccessTokenSuccessFullResponse, $accessTokenSuccessFullResponse);
 }