From dedb1592cb7c016bdc9884702d176d206972927e Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 12 Feb 2020 13:15:54 +0100 Subject: [PATCH] MDL-67644 tool_mobile: Add OAuth 2 providers in disabled features --- admin/tool/mobile/classes/api.php | 27 +++++++++++++++++++++++ admin/tool/mobile/lang/en/tool_mobile.php | 1 + 2 files changed, 28 insertions(+) diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php index a60b8f6b95cbf..d605bfbcf10c0 100644 --- a/admin/tool/mobile/classes/api.php +++ b/admin/tool/mobile/classes/api.php @@ -346,6 +346,7 @@ public static function get_autologin_key() { */ public static function get_features_list() { global $CFG; + require_once($CFG->libdir . '/authlib.php'); $general = new lang_string('general'); $mainmenu = new lang_string('mainmenu', 'tool_mobile'); @@ -355,6 +356,7 @@ public static function get_features_list() { $user = new lang_string('user'); $files = new lang_string('files'); $remoteaddons = new lang_string('remoteaddons', 'tool_mobile'); + $identityproviders = new lang_string('oauth2identityproviders', 'tool_mobile'); $availablemods = core_plugin_manager::instance()->get_plugins_of_type('mod'); $coursemodules = array(); @@ -473,6 +475,31 @@ public static function get_features_list() { $features["$remoteaddons"] = $remoteaddonslist; } + // Display OAuth 2 identity providers. + if (is_enabled_auth('oauth2')) { + $identityproviderslist = array(); + $idps = \auth_plugin_base::get_identity_providers(['oauth2']); + + foreach ($idps as $idp) { + // Only add identity providers that have an ID. + $id = isset($idp['url']) ? $idp['url']->get_param('id') : null; + if ($id != null) { + $identityproviderslist['NoDelegate_IdentityProvider_' . $id] = $idp['name']; + } + } + + if (!empty($identityproviderslist)) { + $features["$identityproviders"] = array(); + + if (count($identityproviderslist) > 1) { + // Include an option to disable them all. + $features["$identityproviders"]['NoDelegate_IdentityProviders'] = new lang_string('all'); + } + + $features["$identityproviders"] = array_merge($features["$identityproviders"], $identityproviderslist); + } + } + return $features; } diff --git a/admin/tool/mobile/lang/en/tool_mobile.php b/admin/tool/mobile/lang/en/tool_mobile.php index e9d2fd81d0a96..83a4e568f2aa1 100644 --- a/admin/tool/mobile/lang/en/tool_mobile.php +++ b/admin/tool/mobile/lang/en/tool_mobile.php @@ -84,6 +84,7 @@ $string['mobilefeatures'] = 'Mobile features'; $string['mobilenotificationsdisabledwarning'] = 'Mobile notifications are not enabled. They should be enabled in Notification settings.'; $string['mobilesettings'] = 'Mobile settings'; +$string['oauth2identityproviders'] = 'OAuth 2 identity providers'; $string['offlineuse'] = 'Offline use'; $string['pluginname'] = 'Moodle app tools'; $string['pluginnotenabledorconfigured'] = 'Plugin not enabled or configured.';