Skip to content

Microsoft Entra ID credentials provider #463

@byewokko

Description

@byewokko

Add support for Microsoft Entra ID as a credentials provider.

Untested ChatGPT snippet:

from msal import ConfidentialClientApplication
import requests

# Configuration
TENANT_ID = "your-tenant-id"
CLIENT_ID = "your-client-id"
CLIENT_SECRET = "your-client-secret"
AUTHORITY = f"https://login.microsoftonline.com/{TENANT_ID}"
SCOPE = ["https://graph.microsoft.com/.default"]
GRAPH_API_ENDPOINT = "https://graph.microsoft.com/v1.0/users"

# Create an MSAL confidential client
app = ConfidentialClientApplication(
    client_id=CLIENT_ID,
    authority=AUTHORITY,
    client_credential=CLIENT_SECRET,
)

# Get token
result = app.acquire_token_for_client(scopes=SCOPE)

if "access_token" in result:
    headers = {"Authorization": f"Bearer {result['access_token']}"}
    users = []
    endpoint = GRAPH_API_ENDPOINT

    while endpoint:
        response = requests.get(endpoint, headers=headers)
        data = response.json()
        users.extend(data.get("value", []))
        endpoint = data.get("@odata.nextLink")  # pagination

    # Print user display names
    for user in users:
        print(f"{user['displayName']} - {user['userPrincipalName']}")
else:
    print("Failed to obtain token.")
    print(result.get("error"))
    print(result.get("error_description"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions