Symfony 2.4/FOSUserBundle-是否可以通过编程方式挂接到登录过程中? [英] Symfony 2.4/FOSUserBundle - is there a way to hook into the login process programatically?

查看:94
本文介绍了Symfony 2.4/FOSUserBundle-是否可以通过编程方式挂接到登录过程中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的项目,该项目使用FOSUserBundle处理与用户相关的所有事情,包括登录系统.现在,我正在构建一个API,希望用户能够通过HTTPS上的JSON通过发送凭据来登录系统.我还希望能够使用_remember_me cookie.

I have a working project that uses the FOSUserBundle to handle all things user related, including logging into the system. Now, I'm building an API, and would like users to be able to log into the system by sending their credentials via JSON over HTTPS. I'd also like to be able to use the _remember_me cookie.

因此,我需要能够将这些JSON解码的凭据或_remember_me cookie发送到FOSUserBundle登录机制,但是我不太确定该怎么做.朝正确方向提出的任何建议或建议,将不胜感激.

So, I need to be able to send either those JSON-decoded credentials or the _remember_me cookie to the FOSUserBundle login mechanism, but I'm not quite sure how to do it. Any suggestions or nudges in the right direction would be greatly appreciated.

推荐答案

您需要创建一个自定义身份验证提供程序和一个安全工厂.这是一项非常高级的任务,但是这里有一个教程可以为您提供帮助. http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html

You need to create a custom authentication provider and a security factory. This is quite an advanced task, but there's a tutorial here that can help you. http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html

在创建工厂类(实现SecurityFactoryInterface)时,请确保将getPosition()分配给http.根据身份验证工厂的位置,将严格按照顺序调用这几个身份验证工厂,因此请记住,remember_me位置-将负责记住我"功能(前提是您的security.yml文件中启用了此功能)早于您要实现的http身份验证.

When you create your factory class (implementing the SecurityFactoryInterface) make sure you assign getPosition() to http. The several authentication factories will be called in a strict order depending on their position, so bear in mind that the remember_me position - that takes care of the remember me functionality (provided it is enabled in your security.yml file) - will kick in earlier than the http authentication you are about to implement.

除了上面的教程之外,您还可以查看并研究以下内置的身份验证工厂,这些工厂可以提供有用的信息:
vendor/symfony/symfony/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php

Besides the tutorial above, you can take a look at and study the following built-in authentication factory that can provide useful information:
vendor/symfony/symfony/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php

这篇关于Symfony 2.4/FOSUserBundle-是否可以通过编程方式挂接到登录过程中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆