示例#1
0
 /**
  * Check setup in Azure.
  */
 public function mode_checksetup()
 {
     $data = new \stdClass();
     $success = false;
     $resource = \local_o365\rest\azuread::get_resource();
     $clientdata = \local_o365\oauth2\clientdata::instance_from_oidc();
     $httpclient = new \local_o365\httpclient();
     $token = \local_o365\oauth2\systemtoken::instance(null, $resource, $clientdata, $httpclient);
     if (empty($token)) {
         throw new \moodle_exception('errorchecksystemapiuser', 'local_o365');
     }
     // Legacy API.
     $legacyapi = new \stdClass();
     $aadapiclient = new \local_o365\rest\azuread($token, $httpclient);
     list($missingperms, $haswrite) = $aadapiclient->check_permissions();
     $legacyapi->missingperms = $missingperms;
     $legacyapi->haswrite = $haswrite;
     // Unified API.
     $unifiedapi = new \stdClass();
     $unifiedapi->active = false;
     $httpclient = new \local_o365\httpclient();
     $unifiedresource = \local_o365\rest\unified::get_resource();
     $token = \local_o365\oauth2\systemtoken::instance(null, $unifiedresource, $clientdata, $httpclient);
     if (empty($token)) {
         throw new \moodle_exception('errorchecksystemapiuser', 'local_o365');
     }
     $unifiedapiclient = new \local_o365\rest\unified($token, $httpclient);
     $unifiedpermsresult = $unifiedapiclient->check_permissions();
     if ($unifiedpermsresult === null) {
         $unifiedapi->active = false;
     } else {
         $unifiedapi->active = true;
         $unifiedapi->missingperms = $unifiedpermsresult;
     }
     $data->legacyapi = $legacyapi;
     $data->unifiedapi = $unifiedapi;
     set_config('azuresetupresult', serialize($data), 'local_o365');
     set_config('unifiedapiactive', (int) $unifiedapi->active, 'local_o365');
     $success = true;
     echo $this->ajax_response($data, $success);
 }
示例#2
0
 /**
  * Check setup in Azure.
  */
 public function mode_checksetup()
 {
     $data = new \stdClass();
     $success = false;
     $enableunifiedapi = optional_param('enableunifiedapi', 0, PARAM_INT);
     set_config('enableunifiedapi', $enableunifiedapi, 'local_o365');
     $chineseapi = optional_param('chineseapi', 0, PARAM_INT);
     set_config('chineseapi', $chineseapi, 'local_o365');
     $aadtenant = required_param('aadtenant', PARAM_TEXT);
     set_config('aadtenant', $aadtenant, 'local_o365');
     $odburl = required_param('odburl', PARAM_TEXT);
     set_config('odburl', $odburl, 'local_o365');
     $resource = \local_o365\rest\azuread::get_resource();
     $clientdata = \local_o365\oauth2\clientdata::instance_from_oidc();
     $httpclient = new \local_o365\httpclient();
     $token = \local_o365\oauth2\systemtoken::instance(null, $resource, $clientdata, $httpclient);
     if (empty($token)) {
         throw new \moodle_exception('errorchecksystemapiuser', 'local_o365');
     }
     // Legacy API.
     $legacyapi = new \stdClass();
     try {
         $aadapiclient = new \local_o365\rest\azuread($token, $httpclient);
         list($missingperms, $haswrite) = $aadapiclient->check_permissions();
         $legacyapi->missingperms = $missingperms;
         $legacyapi->haswrite = $haswrite;
     } catch (\Exception $e) {
         \local_o365\utils::debug($e->getMessage(), 'mode_checksetup:legacy');
         $legacyapi->error = $e->getMessage();
     }
     $data->legacyapi = $legacyapi;
     // Unified API.
     $unifiedapi = new \stdClass();
     $unifiedapi->active = false;
     if (\local_o365\rest\unified::is_enabled() === true) {
         try {
             $httpclient = new \local_o365\httpclient();
             $unifiedresource = \local_o365\rest\unified::get_resource();
             $token = \local_o365\oauth2\systemtoken::instance(null, $unifiedresource, $clientdata, $httpclient);
             if (empty($token)) {
                 throw new \moodle_exception('errorchecksystemapiuser', 'local_o365');
             }
             $unifiedapiclient = new \local_o365\rest\unified($token, $httpclient);
             $unifiedpermsresult = $unifiedapiclient->check_permissions();
             if ($unifiedpermsresult === null) {
                 $unifiedapi->active = false;
             } else {
                 $unifiedapi->active = true;
                 $unifiedapi->missingperms = $unifiedpermsresult;
             }
         } catch (\Exception $e) {
             $unifiedapi->active = false;
             \local_o365\utils::debug($e->getMessage(), 'mode_checksetup:unified');
             $unifiedapi->error = $e->getMessage();
         }
     }
     $data->unifiedapi = $unifiedapi;
     set_config('unifiedapiactive', (int) $unifiedapi->active, 'local_o365');
     set_config('azuresetupresult', serialize($data), 'local_o365');
     $success = true;
     echo $this->ajax_response($data, $success);
 }