@@ -3,15 +3,15 @@ ApiKey Bundle
33
44Creates an avenue for using ApiKey authentication for Symfony2. Requires FOSUserBundle.
55
6- ## Installation
6+ # Installation
77
88Requires composer, install as follows
99
1010``` sh
1111composer require uecode/api-key-bundle dev-master
1212```
1313
14- #### Enable Bundle
14+ ## Enable Bundle
1515
1616Place in your ` AppKernel.php ` to enable the bundle
1717
@@ -36,14 +36,23 @@ uecode_api_key:
3636 parameter_name : some_value # defaults to `api_key`
3737` ` `
3838
39+ ### Update user provider
40+
41+ This bundle provides two ways to work with User model:
42+
43+ 1. use model and user provider provided by this bundle
44+ 2. use custom user provider
45+
46+ ### Use model provided by this bundle
47+
3948#### Entities
4049
4150Assuming you already have a ` User` class that extends the `FOSUserBundle`'s base user model,
4251change that extend, so its extending `Uecode\Bundle\ApiKeyBundle\Model\ApiKeyUser`
4352
4453Then update your schema.
4554
46- # ### Set up security
55+ # ### Change used user provider
4756
4857In your security, change your provider to the service `uecode.api_key.provider.user_provider`
4958
@@ -64,7 +73,30 @@ security:
6473 id: uecode.api_key.provider.user_provider
6574` ` `
6675
67- After adding that, you can now add `api_key : true`, and `stateless: true` to any of your firewalls.
76+
77+ # ## Use custom user provider
78+
79+ To work with this bundle your user provider should implement ```ApiKeyUserProviderInterface```.
80+ It consist of one method for loading user by their apiKey.
81+ You should implement this interface for user provider which used in your api firewall :
82+
83+ ` ` ` php
84+ use Uecode\B undle\A piKeyBundle\S ecurity\A uthentication\P rovider\A piKeyUserProviderInterface;
85+
86+ class MyCustomUserProvider implements ApiKeyUserProviderInterface {
87+ // ...
88+
89+ public function loadUserByApiKey($apiKey)
90+ {
91+ return $this->userManager->findUserBy(array('apiKey' => $apiKey));
92+ }
93+
94+ }
95+ ` ` `
96+
97+ # # Change security settings
98+
99+ You can now add `api_key : true`, and `stateless: true` to any of your firewalls.
68100
69101For Example :
70102
0 commit comments