我试图用symfony和FOSOAuthServerBundle创建一个OAuth服务器。我在跟踪
this tutorial
我在“授权码”部分(也许你应该先检查一下这些部分)。当我打开URL时
PROVIDER_HOST/oauth/v2/auth?client_id=CLIENT_ID&response_type=code&redirect_uri=CLIENT_HOST
在浏览器中,我收到一个ERR\u TOO\u MANY\u重定向错误。以下是我的日志文件的输出:
[2017-10-11 09:50:58]请求。信息:匹配的路线
“fos\u oauth\u server\u授权”。
{“route”:“fos\u oauth\u server\u authorize”,“route\u参数”:{“\u controller”:“fos\OAuthServerBundle\controller\AuthorizeController::authorizeAction”,“\u route”:“fos\u oauth\u server\u authorize”},“request\u uri”:
http://example.de/app_dev.php/oauth/v2/auth?client_id=3_4ip472z6jf6scgoog0kssg8so0sosg0ok400w80ccog0s88gs0&redirect_uri=test.local&response_type=code
“,”method“:“GET”}
[]安全。信息:验证异常为
{“异常”:“[对象]
(Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(代码:
0):在令牌存储中未找到令牌。在
.../供应商/symfony/symfony/src/symfony/Component/Security/Http/Firewall/AccessListener。php:53)“}
[]安全。调试:调用身份验证条目
指向[] []
[2017-10-11 09:51:00]请求。信息:匹配的路线
“acme\u oauth\u server\u auth\u login”。
{“route”:“acme\u oauth\u server\u auth\u login”,“route\u parameters”:{“u controller”:“SsoBundle\controller\SecurityController::loginAction”,“\u route”:“acme\u oauth\u server\u auth\u login”},“request\u uri”:
http://example.de/app_dev.php/oauth/v2/auth_login
[]安全。信息:验证异常为
投掷;重定向到身份验证入口点。
{“异常”:“[对象]
(Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(代码:
0):在令牌存储中未找到令牌。在
.../供应商/symfony/symfony/src/symfony/Component/Security/Http/Firewall/AccessListener。php:53)“}
指向[] []
echo "test"; die();
然而,在AuthorizeController和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)
{
}
}
这是我的安全。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 }
我不得不更改教程中的一些内容,因为它不是万能的。但是现在我不知道这次我能做什么。
有人知道问题出在哪里吗?如果你需要更多的代码,请告诉我。谢谢