import requests

# =========== RELLENA TUS DATOS ===========
TENANT_ID = "b16d289b-fa4c-4578-accd-b308f19bbeb5"
CLIENT_ID = "9956717e-890f-4c61-864a-363ae9e025a9"
CLIENT_SECRET = "OZSBa5Dl9GJkoksoPAvzwwsfC2vHDQuadt"
SCOPE = "https://api.businesscentral.dynamics.com/.default"
# ==========================================

TOKEN_URL = f"https://login.microsoftonline.com/b16d289b-fa4c-4578-accd-b308f19bbeb5/oauth2/v2.0/token"

data = {
    "grant_type": "client_credentials",
    "client_id": CLIENT_ID,
    "client_secret": CLIENT_SECRET,
    "scope": SCOPE,
}

try:
    response = requests.post(TOKEN_URL, data=data)
    response.raise_for_status()
    token = response.json()["access_token"]
    print("Autenticación exitosa. Token obtenido:")
    print(token[:80] + "...")
except Exception as e:
    print("Error al obtener el token:", e)
