You are here

class OpenIDConnectAutoDiscover in OpenID Connect / OAuth client 2.x

OpenID Connect well-known URI discovery service.

Hierarchy

Expanded class hierarchy of OpenIDConnectAutoDiscover

1 file declares its use of OpenIDConnectAutoDiscover
OpenIDConnectClientBase.php in src/Plugin/OpenIDConnectClientBase.php
1 string reference to 'OpenIDConnectAutoDiscover'
openid_connect.services.yml in ./openid_connect.services.yml
openid_connect.services.yml
1 service uses OpenIDConnectAutoDiscover
openid_connect.autodiscover in ./openid_connect.services.yml
Drupal\openid_connect\OpenIDConnectAutoDiscover

File

src/OpenIDConnectAutoDiscover.php, line 13

Namespace

Drupal\openid_connect
View source
class OpenIDConnectAutoDiscover {

  /**
   * The Guzzle client object.
   *
   * @var \Drupal\Core\Http\ClientFactory
   */
  protected $client;

  /**
   * The logger factory.
   *
   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
   */
  protected $logger;

  /**
   * Constructs an OpenIDConnectAutoDiscover object.
   *
   * @param \Drupal\Core\Http\ClientFactory $http_client_factory
   *   A Guzzle client object.
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
   *   The logger factory service.
   */
  public function __construct(ClientFactory $http_client_factory, LoggerChannelFactoryInterface $logger_factory) {
    $this->client = $http_client_factory;
    $this->logger = $logger_factory
      ->get('openid_connect');
  }

  /**
   * Returns request response.
   *
   * @param string $base_url
   *   The well-known configuration base URL.
   * @param string $path
   *   The relative path of the well-known configuration.
   *
   * @return array|bool
   *   A result array or FALSE.
   */
  public function fetch(string $base_url, string $path = '.well-known/openid-configuration') {
    try {
      $response = $this->client
        ->fromOptions([
        'base_uri' => $base_url,
      ])
        ->get($path);
      return Json::decode($response
        ->getBody());
    } catch (RequestException $e) {
      $this->logger
        ->warning('The auto discover URL %url seems to be broken because of error "%error".', [
        '%url' => $base_url,
        '%error' => $e
          ->getMessage(),
      ]);
      return FALSE;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OpenIDConnectAutoDiscover::$client protected property The Guzzle client object.
OpenIDConnectAutoDiscover::$logger protected property The logger factory.
OpenIDConnectAutoDiscover::fetch public function Returns request response.
OpenIDConnectAutoDiscover::__construct public function Constructs an OpenIDConnectAutoDiscover object.