Skip to content

Commit

Permalink
Merge branch 'release/3.0.1'
Browse files Browse the repository at this point in the history
Release/3.0.1
  • Loading branch information
MdNadimHossain committed Dec 23, 2021
2 parents a6419e6 + b6f8832 commit d98a909
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "drupal-module",
"license": "GPL-2.0-or-later",
"require": {
"dpc-sdp/tide_core": "^3.0.0",
"dpc-sdp/tide_core": "^3.0.1",
"dpc-sdp/tide_event": "^3.0.0",
"dpc-sdp/tide_landing_page": "^3.0.0",
"dpc-sdp/tide_media": "^3.0.0",
Expand Down
36 changes: 36 additions & 0 deletions src/Auth/AuthProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace Drupal\tide_authenticated_content\Auth;

use Drupal\jwt\Authentication\Event\JwtAuthEvents;
use Drupal\jwt\Authentication\Event\JwtAuthValidateEvent;
use Drupal\jwt\Authentication\Event\JwtAuthValidEvent;
use Drupal\jwt\Authentication\Provider\JwtAuth;
use Drupal\jwt\Transcoder\JwtDecodeException;
use Symfony\Component\HttpFoundation\Request;

/**
Expand Down Expand Up @@ -41,4 +45,36 @@ public static function getJwtFromRequest(Request $request) {
return $matches[1];
}

/**
* {@inheritdoc}
*/
public function authenticate(Request $request) {
$raw_jwt = self::getJwtFromRequest($request);

// Decode JWT and validate signature.
try {
$jwt = $this->transcoder->decode($raw_jwt);
}
catch (JwtDecodeException $e) {
return NULL;
}

$validate = new JwtAuthValidateEvent($jwt);
// Signature is validated, but allow modules to do additional validation.
$this->eventDispatcher->dispatch(JwtAuthEvents::VALIDATE, $validate);
if (!$validate->isValid()) {
return NULL;
}

$valid = new JwtAuthValidEvent($jwt);
$this->eventDispatcher->dispatch(JwtAuthEvents::VALID, $valid);
$user = $valid->getUser();

if (!$user) {
return NULL;
}

return $user;
}

}
2 changes: 1 addition & 1 deletion src/Controller/AuthenticatedContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function create(
ContainerInterface $container
) {
return new static($container,
$container->get('entity.manager')
$container->get('entity_type.manager')
->getStorage('user'),
$container->get('module_handler'));
}
Expand Down

0 comments on commit d98a909

Please sign in to comment.