[英]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_area
和oauth_authorize
。 由於secured_area
看起來像一個后備,可以捕獲其他防火牆未覆蓋的所有URL,因此您可能希望將其移動到文件末尾,因此最后檢查了它。
我的猜測是secured_area
(不允許匿名訪問?),然后將重定向以請求身份驗證降落在同一防火牆上並因此循環。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.