lyseontech/drupal-external-auth

外部认证用户进入 Drupal

安装: 49

依赖: 0

建议: 0

安全: 0

星星: 0

关注者: 4

分支: 1

类型:package

0.2.1 2019-04-09 22:19 UTC

This package is auto-updated.

Last update: 2024-08-29 05:00:32 UTC


README

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

Drupal External Auth

Composer 包,用于外部认证 Drupal 用户

如果用户已在 Drupal 中存在,则认证该用户。

如果用户在 Drupal 中不存在,则创建该用户并认证。

如何使用?

composer require lyseontech/drupal-external-auth

登录

$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, '='));
}

在 PrefixHash 中,放入用于识别系统哈希密码的前缀哈希。

在 hashPassord 中放入用户的哈希,如果没有则不需要,用户可以通过 Drupal 默认登录页面在 Drupal 中认证,在此字段中输入任何内容。

如果您没有在 Drupal 中实现自定义验证哈希,用户只能通过您的系统访问 Drupal。

登出

$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, '='));
}