繁体   English   中英

Symfony FOSOAuthServerBundle ERR_TOO_MANY_REDIRECTS

[英]Symfony FOSOAuthServerBundle ERR_TOO_MANY_REDIRECTS

我正在尝试使用symfony和FOSOAuthServerBundle捆绑包制作OAuth服务器。 我正在学习本教程,并且在“授权代码”部分中(也许您应该在此之前进行检查)。 当我在浏览器中打开URL PROVIDER_HOST/oauth/v2/auth?client_id=CLIENT_ID&response_type=code&redirect_uri=CLIENT_HOST时,出现ERR_TOO_MANY_REDIRECTS错误。 这是我的日志文件的输出:

[2017-10-11 09:50:58] request.INFO:匹配的路由“ fos_oauth_server_authorize”。 {“ route”:“ fos_oauth_server_authorize”,“ route_parameters”:{“ _ controller”:“ FOS \\ OAuthServerBundle \\ Controller \\ AuthorizeController :: authorizeAction”,“ _ route”:“ fos_oauth_server_authorize”},“ request_uri”:“ http:// example .de / app_dev.php / oauth / v2 / auth?client_id = 3_4ip472z6jf6scgoog0kssg8so0sosg0ok400w80ccog0s88gs0&redirect_uri = test.local&response_type = code “,”方法“:”获取“}

[] [2017-10-11 09:50:58] security.INFO:抛出AuthenticationException; 重定向到身份验证入口点。 {“ exception”:“ [对象](Symfony \\ Component \\ Security \\ Core \\ Exception \\ AuthenticationCredentialsNotFoundException(代码:0):在TokenStorage中找不到令牌。位于... / vendor / symfony / symfony / src / Symfony /Component/Security/Http/Firewall/AccessListener.php:53)“}

[] [2017-10-11 09:50:58] security.DEBUG:调用身份验证入口点。 [] []

[2017-10-11 09:51:00] request.INFO:匹配的路由“ acme_oauth_server_auth_login”。 {“ route”:“ acme_oauth_server_auth_login”,“ route_parameters”:{“ _ controller”:“ SsoBundle \\ Controller \\ SecurityController :: loginAction”,“ _ route”:“ acme_oauth_server_auth_login”},“ request_uri”:“ http://example.de /app_dev.php/oauth/v2/auth_login “,”方法“:” GET“}

[] [2017-10-11 09:51:00] security.INFO:抛出AuthenticationException; 重定向到身份验证入口点。 {“ exception”:“ [对象](Symfony \\ Component \\ Security \\ Core \\ Exception \\ AuthenticationCredentialsNotFoundException(代码:0):在TokenStorage中找不到令牌。位于... / vendor / symfony / symfony / src / Symfony /Component/Security/Http/Firewall/AccessListener.php:53)“}

[] [2017-10-11 09:51:00] security.DEBUG:调用身份验证入口点。 [] []

现在,最后3个日志重复执行...我试图用echo "test"; die();调试它echo "test"; die(); echo "test"; die(); 在AuthorizeController和SecurityController中,但是甚至无法正常工作。

这是我的SecurityController:

namespace SsoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;

class SecurityController extends Controller
{
    public function loginAction(Request $request)
    {

        $session = $request->getSession();

        if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
            $error = $request->attributes->get(Security::AUTHENTICATION_ERROR);
        } elseif (null !== $session && $session->has(Security::AUTHENTICATION_ERROR)) {
            $error = $session->get(Security::AUTHENTICATION_ERROR);
            $session->remove(Security::AUTHENTICATION_ERROR);
        } else {
            $error = '';
        }

        if ($error) {
            $error = $error->getMessage(
            ); // WARNING! Symfony source code identifies this line as a potential security threat.
        }

        $lastUsername = (null === $session) ? '' : $session->get(Security::LAST_USERNAME);

        return $this->render(
            'SsoBundle:Security:login.html.twig',
            array(
                'last_username' => $lastUsername,
                'error' => $error,
            )
        );
    }

    public function loginCheckAction(Request $request)
    {

    }
}

这是我的security.yml:

security:

    # https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
    providers:
        in_memory:
            memory: ~
        user_provider:
            id: platform.user.provider

    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        oauth_token:
            pattern:    ^/oauth/v2/token
            security:   false

        secured_area:
            pattern:    ^/
            form_login:
                provider: user_provider
                check_path: /oauth/v2/auth_login_check
                login_path: /oauth/v2/auth_login
            logout:
                path:   /logout
                target: /

        oauth_authorize:
            pattern:    ^/oauth/v2/auth
            form_login:
                provider: user_provider
                check_path: /oauth/v2/auth_login_check
                login_path: /oauth/v2/auth_login
            anonymous: true

        api:
            pattern:    ^/api/.*
            fos_oauth:  true
            stateless:  true

        main:
            anonymous: ~
            # activate different ways to authenticate

            # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
            #http_basic: ~

            # https://symfony.com/doc/current/security/form_login_setup.html
            #form_login: ~

    encoders:
        SsoBundle\Entity\User:
            algorithm:        sha1
            encode_as_base64: false
            iterations:       1

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    access_control:
        - { path: ^/api, roles: [ IS_AUTHENTICATED_FULLY ] }
        - { path: ^/demo/secured/hello/admin/, roles: ROLE_ADMIN }
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }

我必须更改本教程中的某些内容,因为它不能正常工作。 但是现在我不知道这次我能做什么。

有人知道可能是什么问题吗? 如果您需要更多代码,请告诉我。 谢谢!

Symfony将选择第一个适合url的防火墙。 在您的情况下,多个防火墙将与^/oauth/v2/auth匹配。 secured_areaoauth_authorize 由于secured_area看起来像一个后备,可以捕获其他防火墙未覆盖的所有URL,因此您可能希望将其移动到文件末尾,因此最后检查了它。

我的猜测是secured_area (不允许匿名访问?),然后将重定向以请求身份验证降落在同一防火墙上并因此循环。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM