如何在第三方应用程序中使用会话 Symfony2 执行授权



我对以下情况有问题:
在我的Symfony2应用程序中,登录的用户打开第三方应用程序(TinyMCE的文件)。如何使用SF2应用程序的凭据授权用户?

如果用户在登录页面上检查remember_me,则工作:

//Bootstrap of 3rd party app
require_once('../../../app/bootstrap.php.cache');
require_once('../../../app/AppKernel.php');
$kernel = new AppKernel('prod', false);
$request = SymfonyComponentHttpFoundationRequest::createFromGlobals();
$container = $kernel->getContainer();
if(false == $container->get('security.context')->isGranted('ROLE_USER'))
{
  $response = new SymfonyComponentHttpFoundationRedirectResponse('http://'.$request->getHost());
  return $response->send();
}

但是,如果未使用remember_me登录,则会导致重定向到登录页面。

在security.yml上,您可以设置记住我默认为"是"。这是参考,我不想复制整个配置文件。

Symfony 參考資料

我的建议是将tinyMCE(您网站上的任何第三方应用程序)放在防火墙后面。

#security.yml
firewalls:
    tiny_mce:
        pattern: ^/path/to/your/tinymce/dir
        http_basic: # Any authentication provider here
            realm: "Secured Demo Area"

当用户打开 tinymce 时,浏览器将请求 http://example.com/path/to/your/tinymce/dir/tinymcefile.html。symfony将需要用户进行身份验证,因为你在你的security.yml中提到了这个路径。

更新

当您登录到开发环境,然后尝试从生产环境或反向访问路径时,也可能会出现此问题!我看到对于小 mce 你使用 dev env。检查您之前登录的环境。

最新更新