Created
March 18, 2022 11:50
-
-
Save vishwac09/977d1c0b5f6d1af0f7df81f56106af85 to your computer and use it in GitHub Desktop.
AuthZeroService snippet for writing Unit Test cases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\authzero\Service; | |
use Drupal\Core\Config\ConfigFactoryInterface; | |
/** | |
* Set of utility functions. | |
*/ | |
class AuthZeroService { | |
/** | |
* The authZero Settings. | |
* | |
* @var array | |
*/ | |
protected $auth0; | |
/** | |
* Defining constructor for Auth0. | |
* | |
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory | |
* The config factory object. | |
*/ | |
public function __construct(ConfigFactoryInterface $config_factory) { | |
$this->auth0 = $config_factory->get('authzero.settings'); | |
} | |
/** | |
* User logout Link, for auth0. | |
* | |
* @param string|null $error | |
* The error messages. | |
* | |
* @return string | |
* The logout link. | |
*/ | |
public function getLogoutLink(string $error = NULL): string { | |
return sprintf( | |
'https://%s/v2/logout?client_id=%s&federated=true&returnTo=%s?error_description=%s', | |
$this->auth0->get('domain'), | |
$this->auth0->get('client_id'), | |
\Drupal::request()->getSchemeAndHttpHost() . '/auth0/login', | |
$error | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment