oidc-wp / openid-connect-generic

WordPress plugin to provide an OpenID Connect Generic client
https://wordpress.org/plugins/daggerhart-openid-connect-generic/
261 stars 154 forks source link

Support custom mapping from claim to metadata as configuration #273

Open benvoynick opened 3 years ago

benvoynick commented 3 years ago

The plugin provides for mapping additional data from claims using code via the openid-connect-generic-update-user-using-current-claim hook. It would be nice to to allow for configuration of custom mapping from claims to WordPress user metadata in settings.

E.g. a user could set the following as configuration data via the settings form:

my_claim_info -> my_metadata_field my_other_claim_field -> my_other_metadata_field

Rather than having to write the code for the above hook to perform that mapping.

Would y'all be open to a PR for adding this to the plugin? Reading some of the issue queue and seeing folks encouraged to use the hook, I'm guessing this might be considered outside the scope of this plugin, but thought I should ask.

yoannsaludes commented 2 years ago

Hello Ben, I am hitting the same road bump on my project and I'd really like to stick with this plugin for OpenID Auth. a big +1 on this. Willing to sponsor the author.

timnolte commented 2 years ago

The plugin also provides settings hooks so that you can also write an add-on to provide additional settings and functionality. It's a pretty tall order to attempt to provide this sort of mapping dynamically for every possible IDP. Even miniOrange, which would be considered "competition", has multiple variations of their plugins which are custom for specific IDPs. The goal of this plugin is to keep within the "generic" realm but then provide hooks for developers to tune/customize for their needs. I have put together add-ons for both Keycloak and Azure AD to provide user role mapping capabilities which are managed via custom settings added to the plugin settings screen

yoannsaludes commented 2 years ago

Thank you very much Tim. I have noticed afterwards only, while reading the code of openid-connect-generic-client-wrapper.php that there is a hook available named "openid-connect-generic-update-user-using-current-claim" that's exactly what I needed ! I was starting to build a plugin from scratch in order to exploit this hook but my wordpress coding skills are rusty of many years and I am slow.

I see already in the user_meta, that the last_claim already holds the value that I am seeking. it's just a metter of moving this nested value into a proper field now!

Perhaps you've dropped some golden nuggets that are also using this hook on the other plugins you've mentioned? I'll have a look right away :) All the best Yoann

HookedBehemoth commented 7 months ago

openid-connect-mappings.zip

Necrobumping this but I wrote this small plugin that allows this. I have to discard this as AzureB2C turned out to be unusable for what I tried to do with it. Maybe it helps someone.