Loading o365.services.yml +1 −1 Original line number Diff line number Diff line services: o365.authentication: class: Drupal\o365\AuthenticationService arguments: [ '@config.factory', '@tempstore.private', '@o365.constants', '@o365.logger', '@request_stack', '@o365.helpers', '@current_user', '@externalauth.authmap' ] arguments: [ '@config.factory', '@tempstore.private', '@o365.constants', '@o365.logger', '@request_stack', '@o365.helpers', '@current_user', '@externalauth.authmap', '@messenger' ] o365.constants: class: Drupal\o365\ConstantsService arguments: [ '@config.factory', '@request_stack', '@o365.helpers' ] Loading src/AuthenticationService.php +20 −7 Original line number Diff line number Diff line Loading @@ -3,14 +3,17 @@ namespace Drupal\o365; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Messenger\Messenger; use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\TempStore\PrivateTempStoreFactory; use Drupal\Core\Url; use Drupal\externalauth\Authmap; use League\OAuth2\Client\Provider\Exception\IdentityProviderException; use League\OAuth2\Client\Provider\GenericProvider; use League\OAuth2\Client\Token\AccessTokenInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; /** * Service used to authenticate users between Office 365 and Drupal. Loading Loading @@ -115,6 +118,13 @@ class AuthenticationService implements AuthenticationServiceInterface { */ protected $helperService; /** * The messenger. * * @var \Drupal\Core\Messenger\Messenger */ protected $messenger; /** * Constructs a new AuthenticationService object. * Loading @@ -134,8 +144,10 @@ class AuthenticationService implements AuthenticationServiceInterface { * The account proxy for the current user. * @param \Drupal\externalauth\Authmap $authmap * The auth map. * @param \Drupal\Core\Messenger\Messenger $messenger * The messenger class. */ public function __construct(ConfigFactoryInterface $configFactory, PrivateTempStoreFactory $tempStoreFactory, ConstantsService $constantsService, O365LoggerServiceInterface $loggerService, RequestStack $requestStack, HelperService $helperService, AccountProxyInterface $accountProxy, Authmap $authmap) { public function __construct(ConfigFactoryInterface $configFactory, PrivateTempStoreFactory $tempStoreFactory, ConstantsService $constantsService, O365LoggerServiceInterface $loggerService, RequestStack $requestStack, HelperService $helperService, AccountProxyInterface $accountProxy, Authmap $authmap, Messenger $messenger) { $this->configFactory = $configFactory; $this->apiConfig = $this->configFactory->get('o365.api_settings'); $this->apiSettings = $helperService->getApiConfig(); Loading @@ -147,6 +159,7 @@ class AuthenticationService implements AuthenticationServiceInterface { $this->request = $requestStack->getCurrentRequest(); $this->currentUser = $accountProxy; $this->authmap = $authmap; $this->messenger = $messenger; $this->debug = !empty($this->moduleConfig->get('verbose_logging')); } Loading @@ -155,13 +168,13 @@ class AuthenticationService implements AuthenticationServiceInterface { * {@inheritdoc} */ public function redirectToAuthorizationUrl() { if ($this->currentUser->isAnonymous() && $this->request->getPathInfo() !== '/o365/login') { if ($this->debug) { $message = t('-- Anonymous user, do not redirect'); if ($this->currentUser->isAnonymous() && strstr($this->request->getPathInfo(), '/o365/login') === FALSE) { $message = t('An anonymous user tried to log in using o365, this is not allowed.'); $this->loggerService->debug($message); } return FALSE; $url = Url::fromRoute('user.login'); $response = new TrustedRedirectResponse($url->toString()); return $response->send(); } if ($this->debug) { Loading Loading
o365.services.yml +1 −1 Original line number Diff line number Diff line services: o365.authentication: class: Drupal\o365\AuthenticationService arguments: [ '@config.factory', '@tempstore.private', '@o365.constants', '@o365.logger', '@request_stack', '@o365.helpers', '@current_user', '@externalauth.authmap' ] arguments: [ '@config.factory', '@tempstore.private', '@o365.constants', '@o365.logger', '@request_stack', '@o365.helpers', '@current_user', '@externalauth.authmap', '@messenger' ] o365.constants: class: Drupal\o365\ConstantsService arguments: [ '@config.factory', '@request_stack', '@o365.helpers' ] Loading
src/AuthenticationService.php +20 −7 Original line number Diff line number Diff line Loading @@ -3,14 +3,17 @@ namespace Drupal\o365; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Messenger\Messenger; use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\TempStore\PrivateTempStoreFactory; use Drupal\Core\Url; use Drupal\externalauth\Authmap; use League\OAuth2\Client\Provider\Exception\IdentityProviderException; use League\OAuth2\Client\Provider\GenericProvider; use League\OAuth2\Client\Token\AccessTokenInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; /** * Service used to authenticate users between Office 365 and Drupal. Loading Loading @@ -115,6 +118,13 @@ class AuthenticationService implements AuthenticationServiceInterface { */ protected $helperService; /** * The messenger. * * @var \Drupal\Core\Messenger\Messenger */ protected $messenger; /** * Constructs a new AuthenticationService object. * Loading @@ -134,8 +144,10 @@ class AuthenticationService implements AuthenticationServiceInterface { * The account proxy for the current user. * @param \Drupal\externalauth\Authmap $authmap * The auth map. * @param \Drupal\Core\Messenger\Messenger $messenger * The messenger class. */ public function __construct(ConfigFactoryInterface $configFactory, PrivateTempStoreFactory $tempStoreFactory, ConstantsService $constantsService, O365LoggerServiceInterface $loggerService, RequestStack $requestStack, HelperService $helperService, AccountProxyInterface $accountProxy, Authmap $authmap) { public function __construct(ConfigFactoryInterface $configFactory, PrivateTempStoreFactory $tempStoreFactory, ConstantsService $constantsService, O365LoggerServiceInterface $loggerService, RequestStack $requestStack, HelperService $helperService, AccountProxyInterface $accountProxy, Authmap $authmap, Messenger $messenger) { $this->configFactory = $configFactory; $this->apiConfig = $this->configFactory->get('o365.api_settings'); $this->apiSettings = $helperService->getApiConfig(); Loading @@ -147,6 +159,7 @@ class AuthenticationService implements AuthenticationServiceInterface { $this->request = $requestStack->getCurrentRequest(); $this->currentUser = $accountProxy; $this->authmap = $authmap; $this->messenger = $messenger; $this->debug = !empty($this->moduleConfig->get('verbose_logging')); } Loading @@ -155,13 +168,13 @@ class AuthenticationService implements AuthenticationServiceInterface { * {@inheritdoc} */ public function redirectToAuthorizationUrl() { if ($this->currentUser->isAnonymous() && $this->request->getPathInfo() !== '/o365/login') { if ($this->debug) { $message = t('-- Anonymous user, do not redirect'); if ($this->currentUser->isAnonymous() && strstr($this->request->getPathInfo(), '/o365/login') === FALSE) { $message = t('An anonymous user tried to log in using o365, this is not allowed.'); $this->loggerService->debug($message); } return FALSE; $url = Url::fromRoute('user.login'); $response = new TrustedRedirectResponse($url->toString()); return $response->send(); } if ($this->debug) { Loading