-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.js
More file actions
30 lines (25 loc) · 894 Bytes
/
Node.js
File metadata and controls
30 lines (25 loc) · 894 Bytes
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
const axios = require("axios");
const qs = require("qs");
const clientId = "a8cb8706-86da-431a-8810-f48c932a9b12";
const clientSecret = "qum8Q~V-w0KoqR_3GkJtmS1qkmtBoXDpuZPe8bR0";
const tenantId = "24b547dc-41f1-4776-9af2-e579a0d5eadb";
const url = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`;
const data = qs.stringify({
client_id: clientId,
client_secret: clientSecret,
scope: "https://management.azure.com/.default",
grant_type: "client_credentials",
});
async function getAccessToken() {
try {
const response = await axios.post(url, data, {
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
const accessToken = response.data.access_token;
console.log("Access Token:", accessToken);
return accessToken;
} catch (error) {
console.error("Fehler beim Abrufen des Tokens:", error);
}
}
getAccessToken();