From 7f2cff2ac52073589f50e9e25b3c6e3601f81fc9 Mon Sep 17 00:00:00 2001 From: jsampedro Date: Fri, 19 Jul 2013 10:05:57 +0200 Subject: [PATCH] Adds custom header Authentication method --- DependencyInjection/Configuration.php | 2 +- Resources/views/layout.html.twig | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f049223..e02b2d1 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -70,7 +70,7 @@ class Configuration implements ConfigurationInterface ->isRequired() ->validate() // header|query|request, but only query is implemented for now - ->ifNotInArray(array('query', 'http_basic')) + ->ifNotInArray(array('query', 'http_basic', 'header')) ->thenInvalid("Unknown authentication delivery type '%s'.") ->end() ->end() diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index 87777fc..60d5154 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -26,7 +26,7 @@ - {% if authentication and authentication.delivery in ['query', 'http_basic'] %} + {% if authentication and authentication.delivery in ['query', 'http_basic', 'header'] %} api key: {% endif %} {% if authentication and authentication.delivery in ['http_basic'] %} @@ -271,6 +271,8 @@ beforeSend: function (xhr) { if (authentication_delivery == 'http_basic') { xhr.setRequestHeader('Authorization', 'Basic ' + btoa($('#api_key').val() + ':' + $('#api_pass').val())); + }else if(authentication_delivery == 'header') { + xhr.setRequestHeader(api_key_parameter, $('#api_key').val()); } }, complete: function(xhr) { @@ -372,6 +374,9 @@ $('#api_key').val(api_key); } + {% elseif authentication and authentication.delivery == 'header' %} + var authentication_delivery = '{{ authentication.delivery }}'; + var api_key_parameter = '{{ authentication.name }}'; {% else %} var authentication_delivery = false; {% endif %}