首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >symfony 4.1更新中的双因素身份验证错误

symfony 4.1更新中的双因素身份验证错误
EN

Stack Overflow用户
提问于 2018-10-27 18:55:29
回答 2查看 920关注 0票数 1

这是我的代码示例

代码语言:javascript
复制
/**
 * @Route("/two/factor", name="google-authenticator")      
 */
public function twoFactorAction(Request $request)
{
    $user = $this->getUser();
    $secret = $this->container->get("scheb_two_factor.security.google_authenticator")->generateSecret();
    $user->setGoogleAuthenticatorSecret($secret);
    $url = null;
    if(!empty($user->getGoogleAuthenticatorSecret())){
        $url = $this->container->get("scheb_two_factor.security.google_authenticator")->getUrl($user);
    }

这是错误

在编译容器时,"scheb_two_factor.security.google_authenticator“服务或别名已被删除或内联。要么将其公开,要么停止直接使用容器,转而使用依赖项注入。

效果很好。但是在从symfony 3.4更新到4.1之后,我得到了这个错误。请让我知道如何才能迅速修复它,尊敬。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-27 20:15:23

如前所述,Symfony 4.1允许您将自动配置的服务注入到控制器操作和其他地方。但是,您使用的是scheb/two-factor库的旧版本(2.x),它不定义自动配置的服务。

由于您不能升级到此库的4.x,所以您的选项在某种程度上受到限制。但是,应该可以添加一个编译器传递来根据您的需要修改scheb/two-factor库的配置。

简而言之,编译器Pass应该允许您通过这样的操作将此服务重新定义为公共的:

代码语言:javascript
复制
$container 
    ->getDefinition('scheb_two_factor.security.google_authenticator')
    ->setPublic(true);

您必须参考文档来学习如何实现将编译器传递到应用程序中。

票数 0
EN

Stack Overflow用户

发布于 2018-10-27 19:28:44

您不能再使用from容器,因为访问修饰符。试着用自动装配。

您可以使用此接口GoogleAuthenticatorInterface

它来自您当前使用的包: Scheb,并具有以下名称空间:

代码语言:javascript
复制
Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;

您的方法如下所示:

代码语言:javascript
复制
public function index(GoogleAuthenticatorInterface $twoFactor)
{
    // ...
    $secret = $twoFactor->generateSecret();
}

如果我不清楚的话,我希望这一页能帮助你更多一点。生成秘密

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53025269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档