Skip to content

Commit

Permalink
Document how to configure entity provider
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Feb 24, 2024
1 parent f689df2 commit 5ce39cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
27 changes: 22 additions & 5 deletions docs/3-configuring_the_security_layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@ Step 3: Configuring the security layer

### A) Have a user provider that implements `OAuthAwareUserProviderInterface`

The bundle needs a service that is able to load users based on the user
response of the oauth endpoint. If you have a custom service it should
implement the interface: `HWI\Bundle\OAuthBundle\Security\Core\User\OAuthAwareUserProviderInterface`.
The bundle needs a service that is able to load users based on the user response of the oauth endpoint.

The HWIOAuthBundle also ships with two default implementations:

- `OAuthUserProvider` (service name: `hwi_oauth.user.provider`) - doesn't persist users
- `EntityUserProvider` (service name: `hwi_oauth.user.provider.entity`) - loads users from a database
1. `HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUserProvider` (service name: `hwi_oauth.user.provider`) - doesn't persist users,
2. `HWI\Bundle\OAuthBundle\Security\Core\User\EntityUserProvider` (service name: `hwi_oauth.user.provider.entity`) - loads users from a database.

The `$properties` variable expects array of strings, where key is name of the resource owner (defined in `config/packages/security.yaml`, see below),
and value is property name on the entity (i.e. `App\Entity\User`).

This provider requires additional configuration:
```yaml
# config/services.yaml
services:
hwi_oauth.user.provider.entity:
class: HWI\Bundle\OAuthBundle\Security\Core\User\EntityUserProvider
arguments:
$class: App\Entity\User
$properties:
'facebook': 'facebook'
'google': 'google'
'my_custom_provider': 'myCustomProvider'
```
3. Implement the interface: `HWI\Bundle\OAuthBundle\Security\Core\User\OAuthAwareUserProviderInterface` in custom user provider,

### B) Configure the oauth firewall

Expand Down
6 changes: 5 additions & 1 deletion src/Resources/config/oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
$services->set('hwi_oauth.user.provider', OAuthUserProvider::class);

$services->set('hwi_oauth.user.provider.entity', EntityUserProvider::class)
->args([service('doctrine')]);
->args([
service('doctrine'),
abstract_arg('User entity class name'),
abstract_arg('an array of properties, where key is resource owner name & value is property name in User entity'),
]);

$services->set('hwi_oauth.context_listener.abstract_token_refresher', AbstractRefreshAccessTokenListener::class)
->abstract()
Expand Down

0 comments on commit 5ce39cd

Please sign in to comment.