Skip to content

Commit

Permalink
Added Guzzle proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
dpi committed Nov 5, 2020
1 parent 50ee362 commit 16d0045
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/AuthmanGuzzleClientProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types = 1);

namespace Drupal\authman;

use Drupal\authman\AuthmanInstance\AuthmanOauthInstanceInterface;
use GuzzleHttp\ClientInterface;
use Psr\Http\Message\RequestInterface;

/**
* Constructs a Guzzle client proxy for Authman.
*/
class AuthmanGuzzleClientProxy implements ClientInterface {

/**
* The authman instance.
*
* @var \Drupal\authman\AuthmanInstance\AuthmanOauthInstanceInterface
*/
protected $authmanInstance;

/**
* Constructs a AuthmanGuzzleClientProxy.
*
* @param \Drupal\authman\AuthmanInstance\AuthmanOauthInstanceInterface $authmanInstance
* An authman instance.
*/
public function __construct(AuthmanOauthInstanceInterface $authmanInstance) {
$this->authmanInstance = $authmanInstance;
}

/**
* {@inheritdoc}
*/
public function send(RequestInterface $request, array $options = []) {
return $this->authmanInstance->authenticatedRequest($request->getMethod(), (string) $request->getUri(), $options);
}

/**
* {@inheritdoc}
*/
public function sendAsync(RequestInterface $request, array $options = []) {
throw new \BadMethodCallException();
}

/**
* {@inheritdoc}
*/
public function request($method, $uri, array $options = []) {
throw new \BadMethodCallException();
}

/**
* {@inheritdoc}
*/
public function requestAsync($method, $uri, array $options = []) {
throw new \BadMethodCallException();
}

/**
* {@inheritdoc}
*/
public function getConfig($option = NULL) {
return $this->authmanInstance->getProvider()->getHttpClient()->getConfig($option);
}

}

0 comments on commit 16d0045

Please sign in to comment.