Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ def main():
help="Output file to save JSON data. Writes all JSON collected from calling the Graph API for more info.")
parser.add_argument("--auth-mode", type=str, choices=["device_code", "azure_sdk"], default="device_code",
help="Authentication method: 'device_code' (default) or 'azure_sdk'.")
parser.add_argument("--tenant-id", type=str, help="Isert a Tenant Id for the Tenant that you wish to access", default="common")
args = parser.parse_args()

print_logo()

print("[*] Authenticating to Azure...")

access_token = authenticate_to_azure(auth_mode=args.auth_mode)
access_token = authenticate_to_azure(auth_mode=args.auth_mode, tenant_id=args.tenant_id)

if not access_token:
print(
Expand Down
10 changes: 5 additions & 5 deletions src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

GRAPH_RESOURCE = "https://graph.microsoft.com"
GRAPH_SCOPE = GRAPH_RESOURCE + "/.default"
DEVICE_CODE_URL = "https://login.microsoftonline.com/common/oauth2/devicecode?api-version=1.0"

TOKEN_URL = "https://login.microsoftonline.com/common/oauth2/token?api-version=1.0"


def authenticate_with_device_code():
def authenticate_with_device_code(tenant_id="common"):
"""
Perform the device code flow to authenticate to Azure and obtain an access token.
"""
Expand All @@ -19,7 +19,7 @@ def authenticate_with_device_code():
"resource": GRAPH_RESOURCE
}

device_code_response = requests.post(DEVICE_CODE_URL, data=payload)
device_code_response = requests.post("https://login.microsoftonline.com/"+tenant_id+"/oauth2/devicecode?api-version=1.0", data=payload)
device_code_data = device_code_response.json()

print(Fore.YELLOW + "[!] To authenticate, visit " + Fore.CYAN + "https://microsoft.com/devicelogin" +
Expand Down Expand Up @@ -73,7 +73,7 @@ def authenticate_with_azure_sdk():
return None


def authenticate_to_azure(auth_mode="device_code"):
def authenticate_to_azure(auth_mode="device_code", tenant_id="common"):
"""
Authenticate to Azure using the selected method.

Expand All @@ -89,4 +89,4 @@ def authenticate_to_azure(auth_mode="device_code"):
"[-] Azure SDK authentication failed. Falling back to device code authentication...")

print("[*] Attempting authentication using device code flow...")
return authenticate_with_device_code()
return authenticate_with_device_code(tenant_id)