Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created June 15, 2015 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaverryan/ee47c1710f4feea97217 to your computer and use it in GitHub Desktop.
Save weaverryan/ee47c1710f4feea97217 to your computer and use it in GitHub Desktop.
Updated Application.php for ApiProblem on HTTP Basic
<?php
namespace KnpU\CodeBattle;
// ...
class Application extends SilexApplication
{
// ...
private function configureSecurity()
{
$app = $this;
$this->register(new SecurityServiceProvider(), array(
// ... no changes
));
// register this service, so we can share it
$app['security.entry_point'] = $app->share(function() use ($app) {
return new ApiEntryPoint($app['translator'], $app['api.response_factory']);
});
// setup the HttpBasic "api" firewall to use this entry point
$this['security.entry_point.api.http'] = $app->share(function() use ($app) {
return $app['security.entry_point'];
});
// setup our custom API token authentication
$app['security.authentication_listener.factory.api_token'] = $app->protect(function ($name, $options) use ($app) {
// no changes
// make this use the security.entry_point service
// the class that decides what should happen if no authentication credentials are passed
$this['security.entry_point.'.$name.'.api_token'] = $app->share(function() use ($app) {
return $app['security.entry_point'];
});
return array(
// ...
);
});
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment