/** * @param AccessTokenRequestAwareGrantInterface $grant * @return AccessTokenSuccessfulResponseInterface * @throws TokenException * @throws InvalidArgumentException */ public function obtainAccessToken(AccessTokenRequestAwareGrantInterface $grant) { $this->checkIsGrantSupportClientType($grant, new ClientType($this->config->getClientType())); $accessTokenObtainTemplate = $this->getAccessTokenObtainTemplate(); $accessTokenRequest = $grant->getAccessTokenRequest(); $httpRequest = $accessTokenObtainTemplate->convertAccessTokenRequestToHttpRequest($accessTokenRequest); $httpResponse = $accessTokenObtainTemplate->sendHttpRequest($httpRequest); if (!$accessTokenObtainTemplate->isSuccessfulResponse($httpResponse)) { $accessTokenObtainTemplate->throwTokenException($httpResponse); } $accessTokenSuccessfulResponse = $accessTokenObtainTemplate->convertHttpResponseToAccessTokenSuccessfulResponse($httpResponse); return $accessTokenSuccessfulResponse; }
/** * @param RequestInterface $request * @param array $bodyParams * @throws \Exception */ protected function setClientAuthenticationData(RequestInterface $request, array &$bodyParams) { switch ($this->getConfig()->getClientAuthenticationType()) { case AuthenticationType::REQUEST_BODY: $bodyParams['client_id'] = $this->getConfig()->getClientId(); if ($this->config->getClientType() === ClientType::CONFIDENTIAL_TYPE) { $bodyParams['client_secret'] = $this->getConfig()->getClientSecret(); } break; case AuthenticationType::HTTP_BASIC: $request->addHeader('Authorization', $this->getBasicAuth()); break; default: throw new \Exception('Unrecognized client authentication type.'); } }