function getModuleToken($new = false) { if ($new === false && $this->moduleToken !== null) { return $this->moduleToken; } else { if ($new === false && !empty($_SESSION['api_module_token'])) { $this->moduleToken = $_SESSION['api_module_token']; return $this->moduleToken; } else { $obj = new self(); $obj->rest->removeHttpHeader("Authorization"); $this->last_response = $obj->apiCall("post", API_HOST_URL . "oauth/token", ["client_id" => API_MODULE_CLIENT_ID, "client_secret" => API_MODULE_CLIENT_SECRET, "grant_type" => "client_credentials", "scope" => "scope:oauth.token.verify"], "x-www-form-urlencoded"); if (!empty($this->last_response->access_token)) { $this->setModuleToken($this->last_response); } unset($obj); } } return $this->moduleToken; }