alexandret/phpcas-guard-bundle

适用于 Symfony3.4 及以上版本的 PhpCAS Bundle,使用 guard 进行认证

安装次数: 3,664

依赖关系: 0

建议者: 0

安全性: 0

星标: 9

关注者: 7

分支: 3

开放性问题: 5

类型:symfony-bundle

1.0.2 2020-05-14 09:24 UTC

This package is auto-updated.

Last update: 2024-09-25 05:18:23 UTC


README

PhpCas Bundle 使用 guard 为 symfony 3.4+ 和 4 提供CAS认证

此bundle 不提供 CAS服务器。使用此bundle,您的应用程序将能够使用您的Cas服务器来认证用户。
SymfonyInsight Coverage Status Build Status

安装

步骤 1: 下载 Bundle

打开命令行,进入您的项目目录并执行以下命令以下载此bundle的最新稳定版本

$ composer require "alexandret/phpcas-guard-bundle" "~1"

此命令要求您全局安装了Composer,如Composer文档中的安装章节所述。

步骤 2: 启用 Bundle

通过将其添加到项目 config/bundles.php 文件中注册的bundle列表中,启用此bundle

<?php

return [
    //...
    AlexandreT\Bundle\CasGuardBundle\CasGuardBundle::class => ['all' => true],
];

步骤 3: 启用安全性

更新您的 config\packages\security.yaml 文件

#https://symfony.com.cn/doc/current/reference/configuration/security.html#full-default-configuration
security:
    # ...
    firewalls:
        #Main firewall
        main:
            # We use Guard !
            guard:
                authenticators:
                    # ADD the cas authenticator declared in this bundle
                    - phpcasguard.cas_authenticator
            # The logout path
            logout:
                # This route will be never called because of listener. It will catch it and redirect user.                
                path: /logout
                # ADD the same cas authenticator declared in this bundle to activate logout function
                success_handler: phpcasguard.cas_authenticator  
    # ...

自 Symfony 2.8以来,Guard 提供了一种新的优秀方式来进行认证。我建议您查看这个优秀的教程,了解Guard的功能。本教程解释了如何使用 guard登录表单 生成标准认证。了解后,您只需禁用第5章中实现的登录表单认证器的调用,并用此bundle中声明的 phpcasguard.cas_authenticator 替换它。

步骤 4: 配置 Bundle

创建一个 config\packages\cas_guard.yaml 文件

cas_guard:
    hostname: '%env(CAS_HOSTNAME)%'
    # ...

查看完整的配置文件以完成配置并将其与您的CAS服务器连接。