我正在嘗試使用symfony和FOSOAuthServerBundle包製作OAuth服務器。我正在關注this tutorial,我在「授權碼」部分(也許您應該檢查零件)。當我在瀏覽器中打開URL PROVIDER_HOST/oauth/v2/auth?client_id=CLIENT_ID&response_type=code&redirect_uri=CLIENT_HOST
時,出現ERR_TOO_MANY_REDIRECTS錯誤。下面是從我的日誌文件輸出:Symfony FOSOAuthServerBundle ERR_TOO_MANY_REDIRECTS
[二○一七年十月一十一日九時五十分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」方法「:」GET「}
[] [2017-10-11 09:50:58] security.INFO:一個AuthenticationException被拋出; 拋出;重定向到認證入口點。 (代碼: 0):在TokenStorage中找不到Token,在 .../vendor/symfony/symfony中發現Token。 /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被拋出; 拋出;重定向到認證入口點。 (代碼: 0):在TokenStorage中找不到Token,在 .../vendor/symfony/symfony中發現Token。 /src/Symfony/Component/Security/Http/Firewall/AccessListener.php:53)「}
[] [2017-10-11 09:51:00] security.DEBUG:調用認證條目 指向。 [] []
最後3個數量級重複現在......我曾嘗試與AuthorizeController和SecurityController內echo "test"; die();
調試它,但是這甚至沒有工作。
這裏是我的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 }
我不得不從教程改變一些東西,因爲它不工作的一切。但是現在我不知道我這次能做什麼。
任何人都知道可能是什麼問題?如果您需要更多代碼,請告訴我。謝謝!