simplesamlphp/simplesamlphp-module-memcookie

SimpleSAMLphp 模块,允许与 Auth MemCookie 集成,使其他语言(而非 PHP)编写的 Web 应用程序能够与 SimpleSAMLphp 集成。

安装次数: 5,422,727

依赖: 1

建议者: 0

安全: 0

星标: 5

关注者: 6

分支: 3

开放问题: 1

类型:simplesamlphp-module

v1.3.3 2024-06-20 11:21 UTC

This package is auto-updated.

Last update: 2024-09-21 19:42:28 UTC


README

Build Status Coverage Status Scrutinizer Code Quality Type Coverage Psalm Level

本模块实现了对 SimpleSAMLphp 的 Auth MemCookie 支持功能。这允许您将 SimpleSAMLphp 与非 PHP 编写的 Web 应用程序集成。

AuthMemCookie 通过从 memcache 服务器读取认证数据,并基于此数据中找到的属性设置环境变量来工作。它还允许您使用默认的 Apache 访问控制 功能来限制对您站点的访问。

需求

此模块需要您安装和设置以下要求

安装

一旦您已安装 SimpleSAMLphp,安装此模块非常简单。首先,如果您尚未安装,您需要 下载 Composer。安装 Composer 后,只需在 SimpleSAMLphp 安装根目录中执行以下命令

composer.phar require simplesamlphp/simplesamlphp-module-memcookie:dev-master

其中 dev-master 指示 Composer 从 Git 存储库安装 master 分支。如果您想使用模块的稳定版本,请参阅可用的 版本

配置

接下来,您需要启用模块

config.php 中,搜索 module.enable 键并将 memcookie 设置为 true

    'module.enable' => [ 'memcookie' => true, … ],

使用此模块的第一步是正确配置 Auth MemCookie。以下示例(您也可以在 extra/auth_memcookie.conf 中找到)可能很有帮助

<Location />
    # This is a list of memcache servers which Auth MemCookie
    # should use. 
    # Note that this list must list the same servers as the
    # 'authmemcookie.servers'-option in config.php in the
    # configuration for simpleSAMLphp.
    #
    # The syntax for this option is inherited from: http://docs.libmemcached.org/libmemcached_configuration.html 
    Auth_memCookie_Memcached_Configuration "--SERVER=127.0.0.1:11211"

    # This must be set to 'on' to enable Auth MemCookie for
    # this directory.
    Auth_memCookie_Authoritative on

    # This adjusts the maximum number of data elements in the
    # session data. The default is 10, which can be to low.
    Auth_memCookie_SessionTableSize "40"

    # These two commands are required to enable access control
    # in Apache.
    AuthType Cookie
    AuthName "My Login"

    # This command causes apache to redirect to the given
    # URL when we receive a '401 Authorization Required'
    # error. We redirect to "/simplesaml/module.php/memcookie/auth.php",
    # which initializes a login to the IdP.
    ErrorDocument 401 "/simplesaml/module.php/memcookie/auth.php"
</Location>

<Location /protected>
    # This allows all authenticated users to access the
    # directory. To learn more about the 'Require' command,
    # please look at:
    # https://httpd.apache.ac.cn/docs/2.0/mod/core.html#require
    Require valid-user
</Location>

一旦 Auth MemCookie 已正确配置,您需要通过编辑 config/authmemcookie.php 文件来配置模块本身。将 username 配置选项设置为肯定能收到并唯一标识用户的属性名称。如果需要帮助配置它,请阅读文件中的说明。

如果您已经在 SimpleSAMLphp 中配置了并正在使用一个 auth source,并且所有您的 memcookie 配置选项都是正确的,您就可以开始了!请确保重新加载 Apache,以便它使用新的配置并加载 Auth MemCookie。然后您可以将浏览器指向您在 Apache 中保护的地址,它应该会自动将您重定向到 IdP 进行认证。

为了查看在受保护位置可用的所有环境变量,您可以在其中放入一个像以下这样的 PHP 脚本,并在通过 IdP 认证后从浏览器访问它

<html>
 <body>
  <table>
<?php
    foreach ($_SERVER as $key => $value) {
        echo "   <tr><td>".htmlspecialchars($key)."</td><td>".htmlspecialchars($value)."</td></tr>\n";
    }
?>
  </table>
 </body>
</html>