Commit ca09275e authored by Brad Jones's avatar Brad Jones
Browse files

Issue #3230707 by bradjones1, mrweiner, Taran2L, e0ipso, bucefal91: 5.x broken...

Issue #3230707 by bradjones1, mrweiner, Taran2L, e0ipso, bucefal91: 5.x broken on php 8 due to incompatibility with lcobucci/jwt v4 via league/oauth2-server ^8.2
parent 7ed0076c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -3,11 +3,11 @@
    "description": "The Simple OAuth module for Drupal",
    "type": "drupal-module",
    "require": {
        "league/oauth2-server": "^8.0 < 8.2",
        "lcobucci/jwt": "^3.4",
        "steverhoades/oauth2-openid-connect-server": "^1.1",
        "lcobucci/jwt": "^4",
        "league/oauth2-server": "^8.3",
        "steverhoades/oauth2-openid-connect-server": "^2.4",
        "drupal/consumers": "^1.2",
        "php": ">=7.0"
        "php": ">=7.4"
    },
    "license": "GPL-2.0+",
    "authors": [
+1 −1
Original line number Diff line number Diff line
@@ -845,7 +845,7 @@ class TokenAuthUser implements TokenAuthUserInterface {
  /**
   * {@inheritdoc}
   */
  public function getIterator() {
  public function getIterator(): \Traversable {
    throw new \Exception('Invalid use of getIterator in token authentication.');
  }

+23 −17
Original line number Diff line number Diff line
@@ -2,10 +2,9 @@

namespace Drupal\simple_oauth\Entities;

use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Key\InMemory;
use Lcobucci\JWT\Signer\Rsa\Sha256;
use League\OAuth2\Server\CryptKey;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use League\OAuth2\Server\Entities\Traits\AccessTokenTrait;
use League\OAuth2\Server\Entities\Traits\EntityTrait;
@@ -18,31 +17,38 @@ class AccessTokenEntity implements AccessTokenEntityInterface {
  /**
   * {@inheritdoc}
   */
  public function convertToJWT(CryptKey $privateKey) {
  public function convertToJWT() {
    $private_claims = [];
    \Drupal::moduleHandler()->alter('simple_oauth_private_claims', $private_claims, $this);
    \Drupal::moduleHandler()
      ->alter('simple_oauth_private_claims', $private_claims, $this);
    if (!is_array($private_claims)) {
      $message = 'An implementation of hook_simple_oauth_private_claims_alter ';
      $message .= 'returns an invalid $private_claims value. $private_claims ';
      $message .= 'must be an array.';
      throw new \InvalidArgumentException($message);
    }
    $builder = (new Builder())
      ->setAudience($this->getClient()->getIdentifier())
      ->setId($this->getIdentifier(), TRUE)
      ->setIssuedAt(time())
      ->setNotBefore(time())
      ->setExpiration($this->getExpiryDateTime()->getTimestamp())
      ->setSubject($this->getUserIdentifier())
      ->set('scopes', $this->getScopes());

    $id = $this->getIdentifier();
    $now = new \DateTimeImmutable('@' . \Drupal::time()->getCurrentTime());
    $key_path = $this->privateKey->getKeyPath();
    $key = InMemory::file($key_path);
    $config = Configuration::forSymmetricSigner(new Sha256(), $key);

    $builder = $config->builder()
      ->permittedFor($this->getClient()->getIdentifier())
      ->identifiedBy($id)
      ->withHeader('jti', $id)
      ->issuedAt($now)
      ->canOnlyBeUsedAfter($now)
      ->expiresAt($this->getExpiryDateTime())
      ->relatedTo($this->getUserIdentifier())
      ->withClaim('scopes', $this->getScopes());

    foreach ($private_claims as $claim_name => $value) {
      $builder->set($claim_name, $value);
      $builder->withClaim($claim_name, $value);
    }

    $key = new Key($privateKey->getKeyPath(), $privateKey->getPassPhrase());
    $token = $builder->sign(new Sha256(), $key)->getToken();
    return $token;
    return $builder->getToken($config->signer(), $config->signingKey());
  }

}
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ class ScopeEntity implements ScopeEntityNameInterface {
  /**
   * {@inheritdoc}
   */
  #[\ReturnTypeWillChange]
  public function jsonSerialize() {
    return $this->getIdentifier();
  }
+13 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\simple_oauth\Grant;

use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Psr\Http\Message\ServerRequestInterface;
@@ -69,4 +70,16 @@ class ClientCredentialsOverrideGrant extends ClientCredentialsGrant {
      : NULL;
  }

  /**
   * @inheritDoc
   */
  protected function validateClient(ServerRequestInterface $request) {
    $client = parent::validateClient($request);
    // The client must also have a valid default user.
    if (!$this->getDefaultUser($client)) {
      throw OAuthServerException::serverError('Invalid default user for client.');
    }
      return $client;
  }

}
Loading