Skip to content

Instantly share code, notes, and snippets.

@vishwac09
Created March 18, 2022 11:50
Show Gist options
  • Save vishwac09/977d1c0b5f6d1af0f7df81f56106af85 to your computer and use it in GitHub Desktop.
Save vishwac09/977d1c0b5f6d1af0f7df81f56106af85 to your computer and use it in GitHub Desktop.
AuthZeroService snippet for writing Unit Test cases
<?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