active-directory-b2c-wordpress-plugin-openidconnect
active-directory-b2c-wordpress-plugin-openidconnect copied to clipboard
Allows users to save custom fields created in Azure to users in WP
For example if I want a field called company, I first create the field in Azure, then I add the following code to my Wordpress plugin/functions.php file:
function custom_ms_fields($userID, $payload) {
if (isset($payload['extension_Company']))
update_user_meta($userID, 'company', sanitize_text_field($payload['extension_Company']));
}
add_action('b2c_new_userdata', 'custom_ms_fields', 10, 2);
add_action('b2c_update_userdata', 'custom_ms_fields', 10, 2);
This will save the information the user entered in the company field to the user meta field 'company' in Wordpress
The new commit is needed if I have a Wordpress installation in different languages, and want the user to view the authentication site in the same language as Wordpress. With the committed changes, I have added the following to my functions file:
function npa_azure_lang($authorization_endpoint) {
return $authorization_endpoint . '&lang=' . $_COOKIE['npa_lang'];
}
add_filter('b2c_authorization_endpoint', 'npa_azure_lang');
where $_COOKIE['npa_lang'] is the language identifier.
@peterspliid, I just started using this AD B2C Wordpress plugin and I like your changes for updating user meta fields from the AD B2C custom attributes. May I ask why you require the use of an action hook rather than just calling update_user_meta() in b2c_verify_token() after the calls to wp_insert_user() and wp_update_user(). Is it so you can more easily control which AD B2C custom attributes are added to Wordpress? Thanks for the work on this plugin!
@ArthurDumas Sorry for the late response. Yes you are correct. You might want to map fields from AD B2C to your custom wordpress fields, or process or verify the data before inserting it. It is generally good practice to use actions or filters when it comes to custom data