/**
  * @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;
 }
Example #2
0
 public function testCreateScopeFromParameter()
 {
     $scope = Scope::fromParameter('user_profile email photos');
     $this->assertEquals(new Scope(array('user_profile', 'email', 'photos')), $scope);
 }