【问题标题】:Using Zend Auth with external authentication mechanism将 Zend Auth 与外部身份验证机制一起使用
【发布时间】:2012-08-24 15:18:42
【问题描述】:

我有一个 Drupal 站点和一个 Zend 应用程序。最主要的是 Drupal 站点,存储用户和所有内容。

我希望我的用户在登录 Drupal 时自动登录到 Zend 应用程序。问题是 Drupal 将会话 cookie 更改为 SESS* 其中* 是一些随机的(编辑:不是随机的,而是基于协议和域)字符串。

有什么方法可以告诉 Zend 使用这个 cookie 作为会话标识符并自动记录用户?

【问题讨论】:

  • Drupal 站点和 Zend 应用程序是否共享相同的 URL(包括子域和端口)?
  • 同一个端口是,同一个域是,不同的子域。不过,cookie 是在整个域上设置的,因此可以从两个站点访问它。
  • 您可以编写自己的身份验证适配器(扩展Zend_Auth_Adapter_Abstract)。读取 cookie 并处理身份验证。
  • 我没有看到任何同名的课程。查看 Zend/Auth/Adapter/Abstract.php 但没有这样的文件。注意:使用 Zend 1.11
  • 我的错。你必须实现Zend_Auth_Adapter_Interface

标签: zend-framework drupal zend-auth


【解决方案1】:

您必须编写自己的身份验证适配器:

class YourApp_Auth_Adapter_DrupalBridge implements Zend_Auth_Adapter_Interface
{
    /**
     * @return Zend_Auth_Result
     */
    public function authenticate()
    {
        // Check if the Drupal session is set by reading the cookie.
        // ...

        // Read the current user's login into $username.
        // ...

        // Create the authentication result object.

        // Failure
        if (null === $username) {
            return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, null);
        }

        // Success
        return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $username);
    }
}

然后处理您的身份验证:

$adapter = new YourApp_Auth_Adapter_DrupalBridge();
$result = Zend_Auth::getInstance()->authenticate($adapter);

if ($result->isValid()) {
    // User is logged in
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-08
    • 2012-09-26
    • 2019-03-08
    • 2020-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    • 2020-03-12
    相关资源
    最近更新 更多