/**
  * Detect the proper auth instance based on received user information.
  *
  * @param \auth_oidc\jwt $idtoken JWT ID Token.
  * @return int|null The auth instance ID if found, or null if none found.
  */
 protected function detect_auth_instance($idtoken)
 {
     // Get auth instance.
     $sql = 'SELECT ai.id as instanceid, i.priority as institutionpriority
               FROM {auth_instance} ai
               JOIN {institution} i ON i.name = ai.institution
              WHERE ai.authname = \'oidc\'
           ORDER BY i.priority DESC, ai.priority ASC';
     $instances = get_records_sql_array($sql);
     $catchalls = array();
     $instanceid = null;
     foreach ($instances as $instance) {
         $reqattr = get_config_plugin_instance('auth', $instance->instanceid, 'institutionattribute');
         $reqval = get_config_plugin_instance('auth', $instance->instanceid, 'institutionvalue');
         if (empty($reqattr) || empty($reqval)) {
             $catchalls[$instance->institutionpriority][] = $instance;
         } else {
             // Check if we received specified attribute.
             $userattrval = $idtoken->claim($reqattr);
             if (!empty($userattrval)) {
                 // Match value.
                 if (preg_match('#' . trim($reqval) . '#', $userattrval)) {
                     $instanceid = $instance->instanceid;
                     break;
                 }
             }
         }
     }
     // If no match on attribute, get the instance id of the first catchall by priority.
     if (empty($instanceid)) {
         foreach ($catchalls as $priority => $instances) {
             foreach ($instances as $instance) {
                 $instanceid = $instance->instanceid;
                 break;
             }
             break;
         }
     }
     return $instanceid;
 }
Example #2
0
define('INTERNAL', 1);
define('MENUITEM', 'settings/preferences');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'account');
define('SECTION_PAGE', 'preferences');
require dirname(dirname(__FILE__)) . '/init.php';
define('TITLE', get_string('preferences'));
require_once 'pieforms/pieform.php';
// load up user preferences
$prefs = (object) $USER->accountprefs;
$authobj = AuthFactory::create($USER->authinstance);
// @todo auth preference for a password change screen for all auth methods other than internal
if (method_exists($authobj, 'change_password')) {
    $elements = array('changepassworddesc' => array('value' => '<tr><td colspan="2"><h3>' . get_string('changepassworddesc', 'account') . '</h3></td></tr>'), 'oldpassword' => array('type' => 'password', 'title' => get_string('oldpassword'), 'help' => true, 'autocomplete' => 'off'), 'password1' => array('type' => 'password', 'title' => get_string('newpassword')), 'password2' => array('type' => 'password', 'title' => get_string('confirmpassword')));
} else {
    if ($url = get_config_plugin_instance('auth', $USER->authinstance, 'changepasswordurl')) {
        // @todo contextual help
        $elements = array('changepasswordotherinterface' => array('value' => '<tr><td colspan="2"><h3>' . get_string('changepasswordotherinterface', 'account', $url) . '</h3></td></tr>'));
    } else {
        $elements = array();
    }
}
if ($authobj->authname == 'internal') {
    $elements['changeusernameheading'] = array('value' => '<tr><td colspan="2"><h3>' . get_string('changeusernameheading', 'account') . '</h3></td></tr>');
    $elements['username'] = array('type' => 'text', 'defaultvalue' => $USER->get('username'), 'title' => get_string('changeusername', 'account'), 'description' => get_string('changeusernamedesc', 'account', get_config('sitename')));
}
$elements['accountoptionsdesc'] = array('value' => '<tr><td colspan="2"><h3>' . get_string('accountoptionsdesc', 'account') . '</h3></td></tr>');
$elements['friendscontrol'] = array('type' => 'radio', 'defaultvalue' => $prefs->friendscontrol, 'title' => get_string('friendsdescr', 'account'), 'separator' => '<br>', 'options' => array('nobody' => get_string('friendsnobody', 'account'), 'auth' => get_string('friendsauth', 'account'), 'auto' => get_string('friendsauto', 'account')), 'help' => true);
$elements['wysiwyg'] = array('type' => 'radio', 'defaultvalue' => $prefs->wysiwyg, 'title' => get_string('wysiwygdescr', 'account'), 'separator' => '<br>', 'options' => array(1 => get_string('on', 'account'), 0 => get_string('off', 'account')), 'help' => true);
$elements['messages'] = array('type' => 'radio', 'defaultvalue' => $prefs->messages, 'title' => get_string('messagesdescr', 'account'), 'separator' => '<br>', 'options' => array('nobody' => get_string('messagesnobody', 'account'), 'friends' => get_string('messagesfriends', 'account'), 'allow' => get_string('messagesallow', 'account')), 'help' => true);
$languages = get_languages();
Example #3
0
 /**
  * Get currently configured instance values for a given instance id.
  *
  * @param int $instanceid Auth instance id.
  * @return array Array of configured instance values in the form [key] => [value].
  */
 public static function get_current_instance_config($instanceid)
 {
     $configparams = array('institutionattribute' => '', 'institutionvalue' => '');
     $curconfig = array();
     foreach ($configparams as $key => $default) {
         if (!empty($instanceid)) {
             $saved = get_config_plugin_instance('auth', $instanceid, $key);
             $curconfig[$key] = $saved !== null ? $saved : $default;
         } else {
             $curconfig[$key] = $default;
         }
     }
     return $curconfig;
 }