Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to configure entity provider #1985

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading