Beispiel #1
0
 /**
  * @param AuthorizationRequestInterface $authorization
  * @throws InvalidArgumentException
  */
 public function buildAuthorizationRequestUri(AuthorizationRequestAwareGrantInterface $grant)
 {
     $authorizationEndpointUri = $this->config->getAuthorizationEndpointUri();
     Assertion::notNull($authorizationEndpointUri, 'Authorization endpoint uri is required to build authorization request uri.');
     $request = $grant->getAuthorizationRequest();
     $request->setClientId($this->config->getClientId());
     $query = http_build_query($request->getQueryParameters());
     return "{$authorizationEndpointUri}?{$query}";
 }
Beispiel #2
0
 /**
  * @param array $config
  * array(
  *      'endpoint' => array(
  *          'token_endpoint_uri' => REQUIRED,
  *          'authorization_endpoint_uri' => REQUIRED if we use authorization request
  *      ),
  *      'client' => array(
  *          'type' => DEFAULT 'confidential'
  *          'credentials' => array (
  *              'client_id' => REQUIRED
  *              'client_secret' => REQUIRED if type is 'confidential'
  *          ),
  *          'authentication_type' => DEFAULT 'http_basic'
  *      ),
  *      'parameters' => array(
  *          'scope' => array(
  *              'delimiter' =>
  *          ),
  *      ),
  * }
  */
 public function __construct(array $config)
 {
     //endpoint section
     //TODO: move require check to client obtainAccessToken method
     Assertion::keyExists($config, 'endpoint', 'Endpoint section is required.');
     Assertion::keyExists($config['endpoint'], 'token_endpoint_uri', 'Token endpoint uri is required.');
     //client section
     Assertion::keyExists($config, 'client', 'Client section is required.');
     $clientType = isset($config['client']['type']) ? $config['client']['type'] : $this->config['client']['type'];
     $clientAuthenticationType = isset($config['client']['authentication_type']) ? $config['client']['authentication_type'] : $this->config['client']['authentication_type'];
     Assertion::inArray($clientType, array(ClientType::CONFIDENTIAL_TYPE, ClientType::PUBLIC_TYPE), "Client type must be set to 'confidential' or 'public'.");
     Assertion::inArray($clientAuthenticationType, array(AuthenticationType::HTTP_BASIC, AuthenticationType::REQUEST_BODY), "Client authentication type must be set to 'http_basic' or 'request_body'.");
     if ($clientType === ClientType::PUBLIC_TYPE && $clientAuthenticationType === AuthenticationType::REQUEST_BODY) {
         throw new InvalidArgumentException("HTTP basic authentication type is not allowed for public client.", 0, null, null);
     }
     Assertion::keyExists($config['client'], 'credentials', 'Client credentials section is required.');
     Assertion::keyExists($config['client']['credentials'], 'client_id', 'Client id is required.');
     if ($clientType === ClientType::CONFIDENTIAL_TYPE) {
         Assertion::keyExists($config['client']['credentials'], 'client_secret', 'Client secret is required for confidential client type.');
     }
     $this->config = ArrayUtils::merge($this->config, $config);
 }
 /**
  * @param AuthorizationRequest $request
  */
 public function setAccessTokenRequest(AccessTokenRequestInterface $request)
 {
     Assertion::isInstanceOf($request, 'MostSignificantBit\\OAuth2\\Client\\Grant\\AuthorizationCode\\AccessTokenRequest');
     $this->accessTokenRequest = $request;
 }
 /**
  * @param AccessTokenRequest $request
  */
 public function setAccessTokenRequest(AccessTokenRequestInterface $request)
 {
     Assertion::isInstanceOf($request, 'MostSignificantBit\\OAuth2\\Client\\Grant\\ResourceOwnerPasswordCredentials\\AccessTokenRequest');
     $this->accessTokenRequest = $request;
 }
 protected function setValue($value)
 {
     Assertion::true($this->isValid($value), $this->validationMessage);
     $this->value = $value;
 }
Beispiel #6
0
 protected function validate(array $scopeTokens)
 {
     Assertion::allRegex($scopeTokens, self::SCOPE_TOKEN_REGEXP);
 }
 /**
  * @return array
  */
 public function getQueryParameters()
 {
     $clientId = $this->getClientId();
     Assertion::notNull($clientId, 'clientId is required');
     $params = array('response_type' => $this->getResponseType()->getValue(), 'client_id' => $clientId);
     if ($this->getRedirectUri() !== null) {
         $params['redirect_uri'] = $this->getRedirectUri()->getValue();
     }
     if ($this->getScope() !== null) {
         $params['scope'] = $this->getScope()->getScopeParameter();
     }
     if ($this->getState() !== null) {
         $params['state'] = $this->getState();
     }
     return $params;
 }