IDCI-Consulting / IDCIKeycloakSecurityBundle

Other
46 stars 46 forks source link

Is it possible to retrive a App\Entity\User #33

Open HiroKX opened 1 year ago

HiroKX commented 1 year ago

Hello,

I've successfully implemented the bundle, but I couldn't get any relations of my App\Entity\User. Is there a way to retrieve this?

I've tried with a UserProvider, but something doesn't work properly, I guess...

Thanks for your help.

konandrum commented 1 year ago

Hello, difficult to understand well what you would like to do. If you would like to bind a KeycloakUser with your local user (entity), you can do that by Overide the KeycloakUserProvider.

You can also use an Event listener to change the Session user.

Hope this will help you.

zenobio93 commented 2 months ago

Hello @HiroKX,

For our usecase we needed to store / update the user getting by Keycloak into our database.

We have solved this by writing our own KeycloakUserProvider extending the KnpU\OAuth2ClientBundle\Security\User\OAuthUserProvider and implementing the IDCI\Bundle\KeycloakSecurityBundle\Security\User\KeycloakUserProviderInterface.

Then you can use it as provider:

security:
  providers:
    keycloak_security_provider:
      id: App\Core\Security\User\KeycloakUserProvider

  firewalls:
    main:
      pattern: ^/
      provider: keycloak_security_provider