/** * Check if a service resource is valid. */ public function mode_checkserviceresource() { $data = new \stdClass(); $success = false; $setting = required_param('setting', PARAM_TEXT); $value = required_param('value', PARAM_TEXT); $clientdata = \local_o365\oauth2\clientdata::instance_from_oidc(); $httpclient = new \local_o365\httpclient(); if ($setting === 'aadtenant') { $resource = \local_o365\rest\azuread::get_resource(); $token = \local_o365\oauth2\systemtoken::instance(null, $resource, $clientdata, $httpclient); if (empty($token)) { throw new \moodle_exception('errorchecksystemapiuser', 'local_o365'); } $apiclient = new \local_o365\rest\azuread($token, $httpclient); $data->valid = $apiclient->test_tenant($value); $success = true; } else { if ($setting === 'odburl') { $data->valid = \local_o365\rest\onedrive::validate_resource($value, $clientdata, $httpclient); $success = true; } } echo $this->ajax_response($data, $success); }