lyseontech/drupal-external-auth

External authenticator user into Drupal

0.2.1 2019-04-09 22:19 UTC

This package is auto-updated.

Last update: 2024-10-29 05:40:43 UTC


README

Build Status Coverage Status PHPStan Latest Stable Version Minimum PHP Version License

Drupal External Auth

Composer package to externally authenticate Drupal users

If the user exists in Drupal, authenticates the user.

If the user does not exist in Drupal, it creates the user and authenticates.

How to use?

composer require lyseontech/drupal-external-auth

Login

$response = new Response();
$pdo = new PDO(...);

(new \DrupalExternalAuth\Auth($response, $pdo))->auth([
    'name'     => 'username',
    'pass'     => 'PrefixHash$' . 'hashOfPassord',
    'timezone' => 'America/Sao_Paulo',
    'langcode' => 'pt-br',
    'roles' => ['administrator']
]);

foreach ($response->headers->getCookies() as $cookie) {
    header('Set-Cookie: '.$cookie->getName().strstr($cookie, '='));
}

In PrefixHash, put the prefix hash to identify the hash password from your system.

In hashPassord put the hash for user, if don't is necessary the user authenticate in Drupal by default login page of Drupal, put anything in this field.

If you dont implement custom validation hash in Drupal, the user can only access Drupal through your system.

Logout

$response = new Response();
$pdo = new PDO(...);

(new \DrupalExternalAuth\Auth($response, $pdo))->logout();
foreach ($response->headers->getCookies() as $cookie) {
    header('Set-Cookie: '.$cookie->getName().strstr($cookie, '='));
}