php - 更新到 symfony 4.1 时的两个因素身份验证错误
问题描述
这是我的代码示例
/**
* @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 后,我收到了这个错误。请让我知道我该如何快速修复它。
解决方案
由于访问修饰符,您不能再从容器中使用。尝试使用自动装配。
你可以使用这个接口GoogleAuthenticatorInterface
它来自您当前使用的同一个包:Scheb 并具有以下命名空间:
Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;
您的方法如下所示:
public function index(GoogleAuthenticatorInterface $twoFactor)
{
// ...
$secret = $twoFactor->generateSecret();
}
如果我不清楚,我希望这个页面可以帮助你更多。生成秘密
推荐阅读
- javascript - 定义将在函数调用之后运行的回调的正确方法是什么?
- java - Mongo 模板的 findAndModify 返回空值以添加或更新嵌套元素
- java - 使用 Spring Aspect 监控方法
- java - 自定义字体不会在 canvas.drawText 上改变
- c# - 返回继承了某个类的新类
- javascript - 无法读取未定义的属性“推送”,试图将信息推送到对象中
- mysql - Mysql 使用 WHERE IN 和 JOINS 更新
- node.js - 有“res.status()”吗?
- javascript - 如何将有向图输出传递给 HTML 代码中的 JavaScript 变量
- r - R - 将操作应用于数据表中的多个指定列