簡體   English   中英

Symfony基本HTTP身份驗證不起作用

[英]Symfony basic HTTP authentication not working

在使用Symfony 2.8.14的項目中,我正在使用一個非常基本的設置來啟用Symfony中的基本HTTP身份驗證,如http://symfony.com/doc/2.8/security.html中所述。

security.yml

security:

    encoders:
        Symfony\Component\Security\Core\User\User: plaintext

    providers:
        in_memory:
            memory:
                users:
                    myuser: { password: mypassword, roles: 'ROLE_USER' }

    firewalls:
        default:
            anonymous: ~
            http_basic: ~

    access_control:
        - { path: ^/myroute, roles: ROLE_USER }

在我的本地服務器上訪問/myroute時,系統會提示我HTTP基本身份驗證提示。 但是,輸入正確的憑據后,它只會繼續向我顯示提示。

在遠程服務器上,輸入正確的憑據后,將無限次“重定向”到帶有401狀態代碼的同一路由。

兩台服務器均通過FastCGI在PHP上運行Apache 2.4。 還有其他線程建議添加

# Sets the HTTP_AUTHORIZATION header removed by apache
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

/web/.htaccess ,這/web/.htaccess因為Apache通過FastCGI運行PHP時/web/.htaccess了特定問題。 但是,它已經被合並到symfony/standard-edition (並且也存在於我的.htaccess )。

我不知道還能嘗試什么。

http://php.net/manual/zh/features.http-auth.php上的注釋之一建議添加以下內容:

SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

有幫助。 似乎symfony/standard-edition的默認.htaccess配置不夠(至少在某些環境中如此)。

嘗試在防火牆下指定以下內容:

firewalls:
    default:
        pattern:      ^/myroute
        anonymous: false
        provider: in_memory

希望這個幫助

您必須執行此操作(轉到新行)

providers:
    in_memory:
        memory:
            users:
                myuser:
                    { password: mypassword, roles: 'ROLE_USER' }

或者你也可以像這樣炸開數組

providers:
    in_memory:
        memory:
            users:
                myuser:
                    password: mypassword
                    roles: 'ROLE_USER'

否則,將myuser視為具有值“ {{password:mypassword,角色:'ROLE_USER'}”的字符串”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM