-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh.js
75 lines (64 loc) · 2.59 KB
/
refresh.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import fs from 'fs';
// Fonction pour rafraîchir le token
async function refreshToken() {
const sessionFilePath = './sessionData.json';
// Charger les données de session (accessToken et refreshToken)
const sessionData = JSON.parse(fs.readFileSync(sessionFilePath, 'utf8'));
const refreshToken = sessionData.refreshToken;
const accessToken = sessionData.accessToken;
// URL pour rafraîchir le token
const refreshUrl = 'https://gw.api.animationdigitalnetwork.fr/authentication/refresh';
await fetch(refreshUrl, {
"headers": {
"accept": "*/*",
"accept-language": "fr,fr-FR;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,de-DE;q=0.5,de;q=0.4",
"priority": "u=1, i",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"Referer": "https://animationdigitalnetwork.com/",
"Referrer-Policy": "strict-origin-when-cross-origin"
},
"body": null,
"method": "OPTIONS"
});
const response = await fetch(refreshUrl, {
"headers": {
"accept": "application/json",
"accept-language": "fr",
"authorization": `Bearer ${accessToken}`,
"content-type": "application/json",
"priority": "u=1, i",
"sec-ch-ua": "\"Chromium\";v=\"128\", \"Not;A=Brand\";v=\"24\", \"Microsoft Edge\";v=\"128\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"x-access-token": accessToken,
"x-i18n-platform": "1",
"x-profile-id": "2",
"x-target-distribution": "fr",
"Referer": "https://animationdigitalnetwork.com/",
"Referrer-Policy": "strict-origin-when-cross-origin"
},
"body": `{\"refreshToken\":\"${refreshToken}\"}`,
"method": "POST"
});
// Extraire les nouveaux tokens de la réponse
if (response.ok) {
const data = await response.json();
console.log("token refreshed");
// Vous pouvez ensuite enregistrer les nouveaux tokens dans un fichier si nécessaire
fs.writeFileSync('./sessionData.json', JSON.stringify({
accessToken: data.accessToken,
refreshToken: data.refreshToken
}));
console.log("and saved")
} else {
console.error('token error:', response.status, response.statusText);
throw new Error("Refresh token failed.");
}
}
// Exemple d'utilisation
refreshToken();