Azure AD B2C Connect

Authentication ::: auth_azureb2c
Maintained by Gopal Sharma
The Azure AD B2C Connect plugin provides registering of a new user and single-sign-on functionality using configurable identity providers, scope and custom policies of Azure B2C.

Azure AD B2C Connect 3.11.0.1

Moodle 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 4.0, 4.1
Released: Thursday, 14 October 2021, 2:50 PM

Update SSO

Update SSO issue with other applications like Drupal using the same Azure AD B2C tenants.

Edit Profile

also added an edit/update profile information into Azure AD B2C and reflect the same changes in Moodle. For edit/update profile(Azure AD B2C profile) to work, one needs to do the following
Add the following code to the theme's profile.php and if you are not using the customize page for profile, then add it to the layout page which the profile page will use.



&lt;?php $id_token = ""; if(!empty($_COOKIE['id_token'])) { $id_token = $_COOKIE['id_token']; $idtoken = explode("=",$id_token); } $editcheck = get_user_preferences('auth_azureb2c_edit'); if($editcheck == 0 || $editcheck == 2 ) { if($editcheck == 0) { set_user_preference('auth_azureb2c_edit', 2); header("Refresh:0"); } if($editcheck == 2) { $userid = optional_param('id', null, PARAM_INT); if(!empty($idtoken[1]) &amp;&amp; ($idtoken[0] =="#id_token")) { updateuserazureb2c($userid, $idtoken[1]); $_COOKIE['id_token'] = null; set_user_preference('auth_azureb2c_edit', 1); } } } ?&gt; &lt;?php $url = get_config('auth_azureb2c', 'editprofileendpoint')."&amp;client_id=". get_config('auth_azureb2c', 'clientid')."&amp; nonce=defaultNonce&amp;redirect_uri=". $CFG-&gt;wwwroot."/auth/azureb2c/&amp;scope=openid&amp;response_type=id_token"; ?&gt; <a href="">&lt;?php echo get_string('editmyprofile'); ?&gt;</a>

Add the folloing function to theme's lib.php

function updateuserazureb2c($userid, $id_token) {
    global $CFG, $OUTPUT, $USER, $PAGE, $DB;
    require_once("{$CFG-&gt;dirroot}/auth/azureb2c/classes/loginflow/base.php");
    $idtoken = \auth_azureb2c\jwt::instance_from_encoded($id_token);
    $username = $idtoken-&gt;claim('oid');
    if (!empty($username)) {         
            $firstname = $idtoken-&gt;claim('given_name');
            $lastname = $idtoken-&gt;claim('family_name');
            $country = $idtoken-&gt;claim('country');
            $countryval = "";
            if (!empty($country)) {
                    $countries = get_string_manager()-&gt;get_list_of_countries();
                    foreach ($countries as  $countrykey =&gt; $countryvalue) {
                        $countryb2c = $country;
                        $countrymoodle = $countryvalue;
                        if($countrymoodle == $countryb2c)
                            $countryval = $countrykey;
                    }
            }
        $gender = $idtoken-&gt;claim('extension_WP_Gender');

        $userupdate = new \stdClass;
        $userupdate-&gt;id = $userid;
        if (!empty($firstname))
            $userupdate-&gt;firstname = $firstname;
        if (!empty($lastname))
            $userupdate-&gt;lastname = $lastname;
        if (!empty($countryval))
            $userupdate-&gt;country = $countryval;
        $DB-&gt;update_record('user', $userupdate);

        $USER-&gt;firstname = $firstname;
        $USER-&gt;lastname = $lastname;
        $USER-&gt;country = $countryval;
        return true;
    }
}

Issues

Please post issues for this plugin to: https://github.com/GopalSharma/moodle-auth_azureb2c/issues

Version information

Version build number
2021101400
Version release name
3.11.0.1
Maturity
Stable version
MD5 Sum
b98daf2353fbf0af680375935be95596
Supported software
Moodle 3.5, Moodle 3.6, Moodle 3.7, Moodle 3.8, Moodle 3.9, Moodle 3.10, Moodle 3.11, Moodle 4.0, Moodle 4.1

Version control information

Version control system (VCS)
GIT
VCS repository URL
VCS tag
v3.11.0.1

Default installation instructions for plugins of the type Authentication

  1. Make sure you have all the required versions.
  2. Download and unpack the module.
  3. Place the folder (eg "myauth") in the "auth" subdirectory.
  4. Visit http://yoursite.com/admin to finish the installation