silex

Symfony security return 401 response instead of redirect

元气小坏坏 提交于 2019-11-30 02:14:33
I'm writing an ajax application with ajax authentication and now I started using the symfony security component in silex to handle authentication/authorization. Doing a simple test with a simple configuration, I go to a protected area by the firewall and the response I get is a redirection to the /login page but what I need in my app is a 401 response with possible additional information(in headers or json body) on how to login. $app['security.firewalls'] = [ 'api' => [ 'pattern' => '^/api', 'logout' => ['logout_path'=>'/auth/logout'], 'users' => $app->share(function(Application $app) { return

Twig addFilter using Silex?

主宰稳场 提交于 2019-11-29 19:21:06
问题 What's the right way to hook up a custom filter to Twig when using Silex, but keep the existing twig.options intact? Here's what I mean. I have the following code: $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => dirname(__FILE__).'/view', 'twig.class_path' => dirname(__FILE__).'/vendor/twig/lib', 'twig.options' => array('cache'=>'folder/twig') )); function test() { return 'yay'; } $app['twig']->addFilter('test',new \Twig_Filter_Function('test')); If I run that

Inherit form or add type to each form

笑着哭i 提交于 2019-11-29 06:38:04
I am searching for an easy way to add a bundle of fields to each form. I have found a way to extend the AbstractType and use the buildForm method to add more fields. When creating the form I give the name of my new type ( How to Create a Custom Form Field Type ). In my opinion it is an easy way, but it is restricted to one type per form. Is there a better way to achieve anything like that? I have read the cookbook of symfony, but I have only found stuff how to extend an existing form not how to create an own form "template" with my fields. Have you tried using inheritance? This is really

Symfony security return 401 response instead of redirect

妖精的绣舞 提交于 2019-11-28 23:09:03
问题 I'm writing an ajax application with ajax authentication and now I started using the symfony security component in silex to handle authentication/authorization. Doing a simple test with a simple configuration, I go to a protected area by the firewall and the response I get is a redirection to the /login page but what I need in my app is a 401 response with possible additional information(in headers or json body) on how to login. $app['security.firewalls'] = [ 'api' => [ 'pattern' => '^/api',

Inherit form or add type to each form

北城以北 提交于 2019-11-28 00:03:41
问题 I am searching for an easy way to add a bundle of fields to each form. I have found a way to extend the AbstractType and use the buildForm method to add more fields. When creating the form I give the name of my new type (How to Create a Custom Form Field Type). In my opinion it is an easy way, but it is restricted to one type per form. Is there a better way to achieve anything like that? I have read the cookbook of symfony, but I have only found stuff how to extend an existing form not how to

Silex SecurityServiceProvider throws 'Identifier “security.authentication_providers” is not defined.'

自闭症网瘾萝莉.ら 提交于 2019-11-27 18:22:24
问题 I can't figure out how to use SecurityServiceProvider in Silex . My configuration is: $app['security.firewalls'] = array( 'admin' => array( 'pattern' => '^/_admin/.+', 'form' => array('login_path' => '/_admin/', 'check_path' => '/_admin/login_check'), 'logout' => array('logout_path' => '/_admin/logout'), 'users' => array( 'admin' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsR...'), ), ), ); $app->register(new Silex\Provider\SecurityServiceProvider()); This just throws: Fatal error: Uncaught

CORS preflight request returning HTTP 405

旧城冷巷雨未停 提交于 2019-11-27 06:54:17
问题 I am trying to create a RESTful web service and have gotten stuck on implementing PUT requests. I have tried and failed to follow other answers on this site and various articles from Mozilla. The request is generated from the domain wwwtest.dev-box and it's going to test.dev-box (basically a front-end app calling the back-end app). Here are the headers I have captured from Live HTTP headers: http://test.dev-box/resource/v1/data/user/1 OPTIONS /resource/v1/data/user/1 HTTP/1.1 Host: test.dev

Symfony2 Form Component - creating fields without the forms name in the name attribute

徘徊边缘 提交于 2019-11-26 20:08:59
问题 I'm currently trying to use the Symfony2 Form Component though the Silex microframework. My login form is generated as follows: $app = $this->app; $constraint = new Assert\Collection(array( 'username' => new Assert\NotBlank(), 'password' => new Assert\NotBlank(), )); $builder = $app['form.factory']->createBuilder('form', $data, array('validation_constraint' => $constraint)); $form = $builder ->add('username', 'text', array('label' => 'Username')) ->add('password', 'password', array('label' =>