glpi-mcp-server 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +9 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -29,10 +29,15 @@ if (!config.glpiUrl || !config.clientId || !config.clientSecret || !config.usern
|
|
|
29
29
|
config.glpiUrl = config.glpiUrl.replace(/\/$/, '');
|
|
30
30
|
|
|
31
31
|
let activeToken = null;
|
|
32
|
+
let tokenExpiresAt = 0;
|
|
32
33
|
|
|
33
34
|
// Função para obter ou renovar o token
|
|
34
35
|
async function getValidToken() {
|
|
35
|
-
|
|
36
|
+
const now = Date.now();
|
|
37
|
+
// Renova se não tiver token ou se faltar menos de 60 segundos para expirar
|
|
38
|
+
if (activeToken && now < tokenExpiresAt - 60000) {
|
|
39
|
+
return activeToken;
|
|
40
|
+
}
|
|
36
41
|
|
|
37
42
|
const tokenUrl = `${config.glpiUrl}/api.php/token`;
|
|
38
43
|
const body = new URLSearchParams({
|
|
@@ -41,7 +46,7 @@ async function getValidToken() {
|
|
|
41
46
|
password: config.password,
|
|
42
47
|
client_id: config.clientId,
|
|
43
48
|
client_secret: config.clientSecret,
|
|
44
|
-
scope: 'api'
|
|
49
|
+
scope: 'email user api inventory status graphql'
|
|
45
50
|
});
|
|
46
51
|
|
|
47
52
|
const response = await fetch(tokenUrl, {
|
|
@@ -60,6 +65,8 @@ async function getValidToken() {
|
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
activeToken = data.access_token;
|
|
68
|
+
// expires_in vem em segundos; converte para ms e marca o tempo de expiração
|
|
69
|
+
tokenExpiresAt = now + ((data.expires_in || 3600) * 1000);
|
|
63
70
|
return activeToken;
|
|
64
71
|
}
|
|
65
72
|
|