diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 1908db1..7a03f78 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -28,6 +28,19 @@ class Configuration implements ConfigurationInterface
->children()
->scalarNode('enabled')->defaultTrue()->end()
->scalarNode('endpoint')->defaultValue('/app_dev.php')->end()
+ ->arrayNode('authentication')
+ ->children()
+ ->scalarNode('name')->isRequired()->end()
+ ->scalarNode('delivery')
+ ->isRequired()
+ ->validate()
+ // header|query|request, but only query is implemented for now
+ ->ifNotInArray(array('query'))
+ ->thenInvalid("Unknown authentication delivery type '%s'.")
+ ->end()
+ ->end()
+ ->end()
+ ->end()
->end()
->end()
->end();
diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php
index 1ecae53..321a2cc 100644
--- a/DependencyInjection/NelmioApiDocExtension.php
+++ b/DependencyInjection/NelmioApiDocExtension.php
@@ -36,5 +36,9 @@ class NelmioApiDocExtension extends Extension
$loader->load('formatters.xml');
$loader->load('request_listener.xml');
$loader->load('services.xml');
+
+ if (isset($config['sandbox']['authentication'])) {
+ $container->setParameter('nelmio_api_doc.sandbox.authentication', $config['sandbox']['authentication']);
+ }
}
}
diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php
index 71edc7b..6ab6b15 100644
--- a/Formatter/HtmlFormatter.php
+++ b/Formatter/HtmlFormatter.php
@@ -15,6 +15,11 @@ use Symfony\Component\Templating\EngineInterface;
class HtmlFormatter extends AbstractFormatter
{
+ /**
+ * @var array
+ */
+ private $authentication;
+
/**
* @var string
*/
@@ -35,6 +40,14 @@ class HtmlFormatter extends AbstractFormatter
*/
private $engine;
+ /**
+ * @param array $authentication
+ */
+ public function setAuthentication(array $authentication = null)
+ {
+ $this->authentication = $authentication;
+ }
+
/**
* @param string $apiName
*/
@@ -95,12 +108,13 @@ class HtmlFormatter extends AbstractFormatter
private function getGlobalVars()
{
return array(
- 'apiName' => $this->apiName,
- 'endpoint' => $this->endpoint,
- 'enableSandbox' => $this->enableSandbox,
- 'date' => date(DATE_RFC822),
- 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
- 'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
+ 'apiName' => $this->apiName,
+ 'authentication' => $this->authentication,
+ 'endpoint' => $this->endpoint,
+ 'enableSandbox' => $this->enableSandbox,
+ 'date' => date(DATE_RFC822),
+ 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
+ 'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
);
}
}
diff --git a/README.md b/README.md
index ae19234..cb23ee7 100644
--- a/README.md
+++ b/README.md
@@ -177,6 +177,9 @@ configure this sandbox using the following parameters:
# app/config/config.yml
nelmio_api_doc:
sandbox:
+ authentication: # default null, if set, the value of the api key is read from the query string and appended to every sandbox api call
+ name: access_token
+ delivery: query # only query delivery is supported for now
enabled: true # default: true, you can set this parameter to `false` to disable the sandbox
endpoint: http://sandbox.example.com/ # default: /app_dev.php, use this parameter to define which URL to call through the sandbox
diff --git a/Resources/config/formatters.xml b/Resources/config/formatters.xml
index 21aa93b..42f189c 100644
--- a/Resources/config/formatters.xml
+++ b/Resources/config/formatters.xml
@@ -9,6 +9,7 @@