You are here

class ResourceServer in Simple OAuth (OAuth2) & OpenID Connect 8.4

Same name and namespace in other branches
  1. 8.2 src/Server/ResourceServer.php \Drupal\simple_oauth\Server\ResourceServer
  2. 8.3 src/Server/ResourceServer.php \Drupal\simple_oauth\Server\ResourceServer
  3. 5.x src/Server/ResourceServer.php \Drupal\simple_oauth\Server\ResourceServer

The resource server.

Hierarchy

Expanded class hierarchy of ResourceServer

1 string reference to 'ResourceServer'
simple_oauth.services.yml in ./simple_oauth.services.yml
simple_oauth.services.yml
1 service uses ResourceServer
simple_oauth.server.resource_server in ./simple_oauth.services.yml
Drupal\simple_oauth\Server\ResourceServer

File

src/Server/ResourceServer.php, line 15

Namespace

Drupal\simple_oauth\Server
View source
class ResourceServer implements ResourceServerInterface {

  /**
   * The decorated resource server.
   *
   * @var \League\OAuth2\Server\ResourceServer
   */
  protected $subject;

  /**
   * The message factory.
   *
   * @var \Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface
   */
  protected $messageFactory;

  /**
   * The HTTP foundation factory.
   *
   * @var \Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface
   */
  protected $foundationFactory;

  /**
   * ResourceServer constructor.
   */
  public function __construct(AccessTokenRepositoryInterface $access_token_repository, ConfigFactoryInterface $config_factory, HttpMessageFactoryInterface $message_factory, HttpFoundationFactoryInterface $foundation_factory) {
    try {
      $public_key = $config_factory
        ->get('simple_oauth.settings')
        ->get('public_key');
      $public_key_real = realpath($public_key);
      if ($public_key && $public_key_real) {
        $this->subject = new LeageResourceServer($access_token_repository, $public_key_real);
      }
    } catch (\LogicException $exception) {
      trigger_error($exception, E_USER_WARNING);
    }
    $this->messageFactory = $message_factory;
    $this->foundationFactory = $foundation_factory;
  }

  /**
   * {@inheritdoc}
   */
  public function validateAuthenticatedRequest(Request $request) {
    if (!$this->subject) {
      throw new \LogicException('Unable to create resource server. Make sure public and private keys are correctly configured.');
    }

    // Create a PSR-7 message from the request that is compatible with the OAuth
    // library.
    $psr7_request = $this->messageFactory
      ->createRequest($request);

    // Augment the request with the access token's decoded data or throw an
    // exception if authentication is unsuccessful.
    $output_psr7_request = $this->subject
      ->validateAuthenticatedRequest($psr7_request);

    // Convert back to the Drupal/Symfony HttpFoundation objects.
    return $this->foundationFactory
      ->createRequest($output_psr7_request);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResourceServer::$foundationFactory protected property The HTTP foundation factory.
ResourceServer::$messageFactory protected property The message factory.
ResourceServer::$subject protected property The decorated resource server.
ResourceServer::validateAuthenticatedRequest public function Determine the access token validity. Overrides ResourceServerInterface::validateAuthenticatedRequest
ResourceServer::__construct public function ResourceServer constructor.