Creates an avenue for using ApiKey authentication for Symfony2. Requires FOSUserBundle.
Requires composer, install as follows
composer require uecode/api-key-bundle dev-masterPlace in your AppKernel.php to enable the bundle
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Uecode\Bundle\ApiKeyBundle\UecodeApiKeyBundle(),
);
}Assuming you already have a User class that extends the FOSUserBundle's base user model,
change that extend, so its extending Uecode\Bundle\ApiKeyBundle\Model\ApiKeyUser
Then update your schema.
In your security, change your provider to the service uecode.api_key.provider.user_provider
security:
providers:
db:
id: uecode.api_key.provider.user_provider
# Or
providers:
chain_provider:
chain:
providers: [db, memory]
memory: # .....
db:
id: uecode.api_key.provider.user_providerAfter adding that, you can now add api_key: true, and stateless: true to any of your firewalls.
For Example:
security:
firewalls:
auth:
pattern: ^/api/*
api_key: true
stateless: true
If you want to allow public resources within the firewall's realm for which the clients do not need
to provide an API key, then you can configure force_api_key to false in your config.yml.
uecode_api_key:
force_api_key: false