public function testWithValidErrorParams()
 {
     $params = ['error' => 'access_denied'];
     $response = new AuthorizationResponse($params);
     $exceptionClass = '\\EasyBib\\OAuth2\\Client\\AuthorizationCodeGrant\\Authorization\\AuthorizationErrorException';
     $this->setExpectedException($exceptionClass, 'access_denied');
     $response->getCode();
 }
Exemplo n.º 2
0
 protected function shouldHaveMadeATokenRequest()
 {
     $lastRequest = $this->mockHandler->getLastRequest();
     $this->assertEquals('POST', $lastRequest->getMethod());
     $this->assertEquals($this->apiBaseUrl . '/oauth/token', $lastRequest->getUri());
     $requestBody = $lastRequest->getBody();
     $expectedBody = new MultipartStream([['name' => 'grant_type', 'contents' => 'authorization_code'], ['name' => 'code', 'contents' => $this->authorization->getCode()], ['name' => 'redirect_uri', 'contents' => $this->clientConfig->getParams()['redirect_uri']], ['name' => 'client_id', 'contents' => $this->clientConfig->getParams()['client_id']]], $requestBody->getBoundary());
     $this->assertEquals((string) $expectedBody, (string) $requestBody);
 }
Exemplo n.º 3
0
 /**
  * @param AuthorizationResponse $response
  * @return bool
  * @throws \LogicException
  */
 public function validateResponse(AuthorizationResponse $response)
 {
     if (!$this->isInitiated()) {
         throw new \LogicException('State not initiated');
     }
     if (empty($response->getParams()['state'])) {
         return false;
     }
     return $response->getParams()['state'] == $this->getState();
 }
 /**
  * @return array
  */
 private function getParams()
 {
     $clientConfig = $this->clientConfig->getParams();
     $params = [['name' => 'grant_type', 'contents' => self::GRANT_TYPE], ['name' => 'code', 'contents' => $this->authorizationResponse->getCode()], ['name' => 'redirect_uri', 'contents' => $clientConfig['redirect_uri']], ['name' => 'client_id', 'contents' => $clientConfig['client_id']]];
     $addOptionalParam = function ($key) use(&$params, $clientConfig) {
         if (isset($clientConfig[$key])) {
             $params[] = ['name' => $key, 'contents' => $clientConfig[$key]];
         }
     };
     $addOptionalParam('client_secret');
     $addOptionalParam('resource');
     return $params;
 }