mikoweb / simple-api-key-bundle
Simple Api Key
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.5.9
- friendsofsymfony/user-bundle: ~2.0
- uecode/api-key-bundle: ~3.0
This package is auto-updated.
Last update: 2024-10-25 07:27:34 UTC
README
Installation
Requires composer, install as follows:
composer require mikoweb/simple-api-key-bundle
Enable Bundle
Place in your AppKernel.php to enable the bundle:
// app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Uecode\Bundle\ApiKeyBundle\UecodeApiKeyBundle(), new FOS\UserBundle\FOSUserBundle(), new Mikoweb\Bundle\SimpleApiKeyBundle\MikowebSimpleApiKeyBundle(), ); // ... } }
Configuration
Import following files in config.yml:
imports: # ... - { resource: api_groups.yml } - { resource: api_keys.yml }
Example groups file:
mikoweb_simple_api_key: groups: api_user: roles: - ROLE_API_USER - ROLE_DO_SOMETHING - ROLE_ACCESS_TO_ARTICLES api_extended_user: roles: - ROLE_API_USER - ROLE_DO_SOMETHING - ROLE_ACCESS_TO_ARTICLES - ROLE_EXTENDED_ACCESS
Example keys file:
mikoweb_simple_api_key: keys: normal_key: api_user extended_key: api_extended_user krwntfibN8: api_user
Add following entries to config.yml
# FOSUserBundle fos_user: db_driver: orm firewall_name: api user_class: Mikoweb\Bundle\SimpleApiKeyBundle\Entity\User # UecodeApiKeyBundle uecode_api_key: delivery: header parameter_name: X-Api-Key # SimpleApiKeyBundle mikoweb_simple_api_key: user_class: Mikoweb\Bundle\SimpleApiKeyBundle\Entity\User
Security firewall
security.yml
security: role_hierarchy: ROLE_API_USER: ROLE_USER providers: api_key: id: mikoweb.simple_api_key.api_key_user_provider firewalls: api: pattern: ^/api/* api_key: true stateless: true provider: api_key access_control: - { path: ^/api/, role: ROLE_API_USER }