-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetToken.py
33 lines (26 loc) · 871 Bytes
/
GetToken.py
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
import json
import urllib.request
import urllib.parse
import requests
import csv
import os
import pyodbc
from datetime import datetime
tenantId = '' # Paste your own tenant ID here
appId = '' # Paste your own app ID here
appSecret = '' # Paste your own app secret here
date = datetime.now().strftime("%Y_%m_%d")
url = "https://login.microsoftonline.com/%s/oauth2/token" % (tenantId)
resourceAppIdUri = 'https://api.securitycenter.microsoft.com'
body = {
'resource': resourceAppIdUri,
'client_id': appId,
'client_secret': appSecret,
'grant_type': 'client_credentials'
}
data = urllib.parse.urlencode(body).encode("utf-8")
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
jsonResponse = json.loads(response.read())
aadToken = jsonResponse["access_token"]
print(aadToken) #To Check the raw token value, for Debugging.