-
Notifications
You must be signed in to change notification settings - Fork 6
/
checkmsuser
executable file
·32 lines (28 loc) · 942 Bytes
/
checkmsuser
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
#!/usr/bin/env python3
# check if a given email address has a connected m365 account
import sys
import json
import logging
import requests
def main(email):
response = {"external_idp": False, "valid_account": False}
url = "https://login.microsoftonline.com/common/GetCredentialType"
body = '{"Username":"%s"}' % email
try:
req = requests.post(url, data=body)
except requests.exceptions.RequestException as e:
logging.error("error: %s" % e)
exit(1)
if bool(req.json()["IfExistsResult"]) is False:
response["valid_account"] = True
if bool(req.json()["IfExistsResult"]) is True:
response["valid_account"] = False
if "FederationRedirectUrl" in req.json()["Credentials"]:
response["external_idp"] = True
return response
try:
email = sys.argv[1]
except IndexError:
print("usage: checkmsuser <email>")
exit()
print(json.dumps(main(email), indent=2))