将 'forward' 与 FOSOAuthServerBundle TokenController 一起使用
Using 'forward' with FOSOAuthServerBundle TokenController
我正在定义一个新的控制器作为 JS 应用程序和 OAuth 服务器之间的代理。代码如下:
namespace Acme\SecurityBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class ProxyController extends Controller
{
public function forwardTokenRequestAction(Request $request)
{
if( ! $request->isXmlHttpRequest() )
{
throw WhateverException();
}
$request->request->add( array(
'client_id'=>'...',
'client_secret'=>'...'
));
return $this->forward('FOSOAuthServerBundle:Token:token');
}
}
但我收到以下错误,因为 我转发到的 TokenController 有一个构造函数,需要 OAuth 服务器作为参数:
Catchable Fatal Error: Argument 1 passed to FOS\OAuthServerBundle\Controller\TokenController::__construct() must be an instance of OAuth2\OAuth2, none given
我不知道:
- 我在哪里可以获得这个服务器实例
- 我如何将它传递给 TokenController
- 我的整个方法是否正确是否正确
我会选择 $this->get('fos_oauth_server.controller.token')->tokenAction($request)
(未尝试但应该有效)
请参阅 https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/config/oauth.xml 了解服务定义,并在 DependencyInjection 文件夹中查看别名。 Xdebug 是你的朋友。
如果您在此代理中预先设置 client_secret/client_id 您正在绕过身份验证,那么您可能完全可以跳过身份验证。
您可以使用令牌身份验证(将用户重定向到登录页面)并为您返回访问令牌以供进一步请求。
这对我决定使用哪种类型的身份验证机制有很大帮助
https://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified
我正在定义一个新的控制器作为 JS 应用程序和 OAuth 服务器之间的代理。代码如下:
namespace Acme\SecurityBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class ProxyController extends Controller
{
public function forwardTokenRequestAction(Request $request)
{
if( ! $request->isXmlHttpRequest() )
{
throw WhateverException();
}
$request->request->add( array(
'client_id'=>'...',
'client_secret'=>'...'
));
return $this->forward('FOSOAuthServerBundle:Token:token');
}
}
但我收到以下错误,因为 我转发到的 TokenController 有一个构造函数,需要 OAuth 服务器作为参数:
Catchable Fatal Error: Argument 1 passed to FOS\OAuthServerBundle\Controller\TokenController::__construct() must be an instance of OAuth2\OAuth2, none given
我不知道:
- 我在哪里可以获得这个服务器实例
- 我如何将它传递给 TokenController
- 我的整个方法是否正确是否正确
我会选择 $this->get('fos_oauth_server.controller.token')->tokenAction($request)
(未尝试但应该有效)
请参阅 https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/config/oauth.xml 了解服务定义,并在 DependencyInjection 文件夹中查看别名。 Xdebug 是你的朋友。
如果您在此代理中预先设置 client_secret/client_id 您正在绕过身份验证,那么您可能完全可以跳过身份验证。
您可以使用令牌身份验证(将用户重定向到登录页面)并为您返回访问令牌以供进一步请求。
这对我决定使用哪种类型的身份验证机制有很大帮助 https://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified