entra-agent-id
microsoft/skills
Créer et gérer des identités compatibles OAuth 2.0 pour les agents IA à l'aide de l'API Microsoft Graph (version bêta).
...Développer toutIdentifiant d'agent Microsoft Entra
Créez et gérez des identités compatibles OAuth2 pour les agents IA à l'aide de l'API bêta Microsoft Graph.
API en préversion — Tous les points de terminaison liés à l’identité des agents se trouvent sous
/beta. Non disponibles dans/v1.0.
Avant de commencer
Rechercher microsoft-docs MCP pour consulter la documentation la plus récente sur les identités d'agent :
- Requête : « Configuration de l'identité d'agent Microsoft Entra »
- Vérifiez que les paramètres de l’API correspondent au comportement actuel de la préversion
Modèle conceptuel
Agent Identity Blueprint (application) ← one per agent type/project
└── BlueprintPrincipal (service principal) ← MUST be created explicitly
├── Agent Identity (SP): agent-1 ← one per agent instance
├── Agent Identity (SP): agent-2
└── Agent Identity (SP): agent-3
Prérequis
PowerShell (recommandé pour la configuration interactive)
# Requires PowerShell 7+
Install-Module Microsoft.Graph.Beta.Applications -Scope CurrentUser -Force
Python (pour le provisionnement programmatique)
pip install azure-identity requests
Rôles Entra requis
L'un des rôles suivants : Développeur d'identité d'agent, Administrateur d'identité d'agent ou Administrateur d'application.
Variables d’environnement
AZURE_TENANT_ID=
AZURE_CLIENT_ID=
AZURE_CLIENT_SECRET=
Authentification
⚠️ L'authentification par «
DefaultAzureCredential» n'est PAS prise en charge. Les jetons Azure CLI contiennentDirectory.AccessAsUser.All, ce que les API d’identité d’agent rejettent explicitement (403). Vous DEVEZ utiliser un enregistrement d’application dédié avecclient_credentialsFlow ou vous connecter viaConnect-MgGraphavec des portées déléguées explicites.
PowerShell (autorisations déléguées)
Connect-MgGraph -Scopes @(
"AgentIdentityBlueprint.Create",
"AgentIdentityBlueprint.ReadWrite.All",
"AgentIdentityBlueprintPrincipal.Create",
"User.Read"
)
Set-MgRequestContext -ApiVersion beta
$currentUser = (Get-MgContext).Account
$userId = (Get-MgUser -UserId $currentUser).Id
Python (autorisations d’application)
import os
import requests
from azure.identity import ClientSecretCredential
credential = ClientSecretCredential(
tenant_id=os.environ["AZURE_TENANT_ID"],
client_id=os.environ["AZURE_CLIENT_ID"],
client_secret=os.environ["AZURE_CLIENT_SECRET"],
)
token = credential.get_token("https://graph.microsoft.com/.default")
GRAPH = "https://graph.microsoft.com/beta"
headers = {
"Authorization": f"Bearer {token.token}",
"Content-Type": "application/json",
"OData-Version": "4.0", # Required for all Agent Identity API calls
}
Workflow de base
Étape 1 : Créer un modèle d’identité d’agent
Des promoteurs sont requis et doivent être des objets « User » — les objets « ServicePrincipal » et les groupes sont rejetés.
import subprocess
# Get sponsor user ID (client_credentials has no user context, so use az CLI)
result = subprocess.run(
["az", "ad", "signed-in-user", "show", "--query", "id", "-o", "tsv"],
capture_output=True, text=True, check=True,
)
user_id = result.stdout.strip()
blueprint_body = {
"@odata.type": "Microsoft.Graph.AgentIdentityBlueprint",
"displayName": "My Agent Blueprint",
"[email protected]": [
f"https://graph.microsoft.com/beta/users/{user_id}"
],
}
resp = requests.post(f"{GRAPH}/applications", headers=headers, json=blueprint_body)
resp.raise_for_status()
blueprint = resp.json()
app_id = blueprint["appId"]
blueprint_obj_id = blueprint["id"]
Étape 2 : Créer un BlueprintPrincipal
Cette étape est obligatoire. La création d’un Blueprint n’entraîne PAS la création automatique de son entité de service. Sans cela, la création de l’identité de l’agent échoue avec le message suivant :
400: The Agent Blueprint Principal for the Agent Blueprint does not exist.
sp_body = {
"@odata.type": "Microsoft.Graph.AgentIdentityBlueprintPrincipal",
"appId": app_id,
}
resp = requests.post(f"{GRAPH}/servicePrincipals", headers=headers, json=sp_body)
resp.raise_for_status()
Si vous implémentez des scripts idempotents, vérifiez et créez le BlueprintPrincipal même si le modèle existe déjà (une exécution précédente a peut-être créé le modèle mais s'est interrompue avant la création du Service Principal).
Étape 3 : Créer des identités d’agent
agent_body = {
"@odata.type": "Microsoft.Graph.AgentIdentity",
"displayName": "my-agent-instance-1",
"agentIdentityBlueprintId": app_id,
"[email protected]": [
f"https://graph.microsoft.com/beta/users/{user_id}"
],
}
resp = requests.post(f"{GRAPH}/servicePrincipals", headers=headers, json=agent_body)
resp.raise_for_status()
agent = resp.json()
Référence API
| Opération | Méthode | Point de terminaison | Type OData |
|---|---|---|---|
| Créer un Blueprint | POST |
/applications |
Microsoft.Graph.AgentIdentityBlueprint |
| Créer un BlueprintPrincipal | POST |
/servicePrincipals |
Microsoft.Graph.AgentIdentityBlueprintPrincipal |
| Créer une identité d’agent | POST |
/servicePrincipals |
Microsoft.Graph.AgentIdentity |
| Répertorier les identités d’agent | GET |
/servicePrincipals?$filter=... |
— |
| Supprimer une identité d'agent | DELETE |
/servicePrincipals/{id} |
— |
| Supprimer un modèle | DELETE |
/applications/{id} |
— |
Tous les points de terminaison utilisent l'URL de base : https://graph.microsoft.com/beta
Autorisations requises
| Autorisation | Objectif |
|---|---|
Application.ReadWrite.All |
CRUD du modèle (objets d'application) |
AgentIdentityBlueprint.Create |
Créer de nouveaux Blueprints |
AgentIdentityBlueprint.ReadWrite.All |
Lire/mettre à jour des Blueprints |
AgentIdentityBlueprintPrincipal.Create |
Créer des BlueprintPrincipals |
AgentIdentity.Create.All |
Créer des identités d’agent |
AgentIdentity.ReadWrite.All |
Lire/mettre à jour les identités d’agent |
Il existe 18 autorisations d'application Graph spécifiques aux identités d'agent. Découvrez-les toutes :
az ad sp show --id 00000003-0000-0000-c000-000000000000 \
--query "appRoles[?contains(value, 'AgentIdentity')].{id:id, value:value}" -o json
Accorder le consentement de l'administrateur (requis pour les autorisations d'application) :
az ad app permission admin-consent --id
Le consentement de l’administrateur peut échouer avec un code d’erreur 404 si l’entité de service n’a pas été répliquée. Réessayez avec un délai de 10 à 40 secondes.
Nettoyage
# Delete Agent Identity
requests.delete(f"{GRAPH}/servicePrincipals/{agent['id']}", headers=headers)
# Delete BlueprintPrincipal (get SP ID first)
sps = requests.get(
f"{GRAPH}/servicePrincipals?$filter=appId eq '{app_id}'",
headers=headers,
).json()
for sp in sps.get("value", []):
requests.delete(f"{GRAPH}/servicePrincipals/{sp['id']}", headers=headers)
# Delete Blueprint
requests.delete(f"{GRAPH}/applications/{blueprint_obj_id}", headers=headers)
Meilleures pratiques
- Créez toujours BlueprintPrincipal après Blueprint — il n’est pas créé automatiquement ; mettez en place des vérifications d’idempotence sur les deux
- Utilisez des objets User comme sponsors — les ServicePrincipals et les groupes sont rejetés
- Gérez les délais de propagation des autorisations : après le consentement de l’administrateur, attendez entre 30 et 120 secondes ; réessayez avec un délai de réessai en cas d’erreur 403
- Incluez l’en-tête «
OData-Version: 4.0» dans chaque requête Graph - Utilisez la fédération d’identités de charge de travail pour l’authentification en production — pour le développement local, utilisez un secret client sur le Blueprint (voir references/oauth2-token-flow.md)
- Configurer l’
identifierUrissur le Blueprint avant d’utiliser la délimitation de portée OAuth2 (api://{app-id}) - N’utilisez jamais de jetons Azure CLI pour les appels API — ils contiennent
Directory.AccessAsUser.Allce qui entraîne un rejet catégorique - Vérifiez l’existence des ressources avant de les créer — mettez en œuvre un provisionnement idempotent
Références
| Fichier | Contenu |
|---|---|
| references/oauth2-token-flow.md | Flux de jetons en production (identité gérée + WIF) et en développement local (secret client) |
| references/known-limitations.md | 29 problèmes connus classés par catégorie (tirés de la page officielle des problèmes connus de la préversion) |
| references/sdk-sidecar.md | SDK Microsoft Entra pour AgentID — points de terminaison, modèles d’agents tiers, déploiement Docker/K8s, sécurité |
Liens externes
| Ressource | URL |
|---|---|
| Guide d’installation officiel | https://learn.microsoft.com/en-us/entra/agent-id/identity-platform/agent-id-setup-instructions |
| Configuration guidée par IA | https://learn.microsoft.com/en-us/entra/agent-id/identity-platform/agent-id-ai-guided-setup |
| SDK Microsoft Entra pour AgentID — Présentation | https://learn.microsoft.com/en-us/entra/msidweb/agent-id-sdk/overview |
| SDK Microsoft Entra pour AgentID — Points de terminaison | https://learn.microsoft.com/en-us/entra/msidweb/agent-id-sdk/endpoints |
---
name: entra-agent-id
description: Create and manage OAuth2-capable identities for AI agents using Microsoft Graph beta API.
---
# Microsoft Entra Agent ID
Create and manage OAuth2-capable identities for AI agents using Microsoft Graph beta API.
> **Preview API** — All Agent Identity endpoints are under `/beta` only. Not available in `/v1.0`.
## Before You Start
Search `microsoft-docs` MCP for the latest Agent ID documentation:
- Query: "Microsoft Entra agent identity setup"
- Verify: API parameters match current preview behavior
## Conceptual Model
```
Agent Identity Blueprint (application) ← one per agent type/project
└── BlueprintPrincipal (service principal) ← MUST be created explicitly
├── Agent Identity (SP): agent-1 ← one per agent instance
├── Agent Identity (SP): agent-2
└── Agent Identity (SP): agent-3
```
## Prerequisites
### PowerShell (recommended for interactive setup)
```powershell
# Requires PowerShell 7+
Install-Module Microsoft.Graph.Beta.Applications -Scope CurrentUser -Force
```
### Python (for programmatic provisioning)
```bash
pip install azure-identity requests
```
### Required Entra Roles
One of: **Agent Identity Developer**, **Agent Identity Administrator**, or **Application Administrator**.
## Environment Variables
```bash
AZURE_TENANT_ID=<your-tenant-id>
AZURE_CLIENT_ID=<app-registration-client-id>
AZURE_CLIENT_SECRET=<app-registration-secret>
```
## Authentication
> **⚠️ `DefaultAzureCredential` is NOT supported.** Azure CLI tokens contain
> `Directory.AccessAsUser.All`, which Agent Identity APIs explicitly reject (403).
> You MUST use a dedicated app registration with `client_credentials` flow or
> connect via `Connect-MgGraph` with explicit delegated scopes.
### PowerShell (delegated permissions)
```powershell
Connect-MgGraph -Scopes @(
"AgentIdentityBlueprint.Create",
"AgentIdentityBlueprint.ReadWrite.All",
"AgentIdentityBlueprintPrincipal.Create",
"User.Read"
)
Set-MgRequestContext -ApiVersion beta
$currentUser = (Get-MgContext).Account
$userId = (Get-MgUser -UserId $currentUser).Id
```
### Python (application permissions)
```python
import os
import requests
from azure.identity import ClientSecretCredential
credential = ClientSecretCredential(
tenant_id=os.environ["AZURE_TENANT_ID"],
client_id=os.environ["AZURE_CLIENT_ID"],
client_secret=os.environ["AZURE_CLIENT_SECRET"],
)
token = credential.get_token("https://graph.microsoft.com/.default")
GRAPH = "https://graph.microsoft.com/beta"
headers = {
"Authorization": f"Bearer {token.token}",
"Content-Type": "application/json",
"OData-Version": "4.0", # Required for all Agent Identity API calls
}
```
## Core Workflow
### Step 1: Create Agent Identity Blueprint
Sponsors are required and **must be User objects** — ServicePrincipals and Groups are rejected.
```python
import subprocess
# Get sponsor user ID (client_credentials has no user context, so use az CLI)
result = subprocess.run(
["az", "ad", "signed-in-user", "show", "--query", "id", "-o", "tsv"],
capture_output=True, text=True, check=True,
)
user_id = result.stdout.strip()
blueprint_body = {
"@odata.type": "Microsoft.Graph.AgentIdentityBlueprint",
"displayName": "My Agent Blueprint",
"[email protected]": [
f"https://graph.microsoft.com/beta/users/{user_id}"
],
}
resp = requests.post(f"{GRAPH}/applications", headers=headers, json=blueprint_body)
resp.raise_for_status()
blueprint = resp.json()
app_id = blueprint["appId"]
blueprint_obj_id = blueprint["id"]
```
### Step 2: Create BlueprintPrincipal
> **This step is mandatory.** Creating a Blueprint does NOT auto-create its
> service principal. Without this, Agent Identity creation fails with:
> `400: The Agent Blueprint Principal for the Agent Blueprint does not exist.`
```python
sp_body = {
"@odata.type": "Microsoft.Graph.AgentIdentityBlueprintPrincipal",
"appId": app_id,
}
resp = requests.post(f"{GRAPH}/servicePrincipals", headers=headers, json=sp_body)
resp.raise_for_status()
```
If implementing idempotent scripts, check for and create the BlueprintPrincipal
even when the Blueprint already exists (a previous run may have created the Blueprint
but crashed before creating the SP).
### Step 3: Create Agent Identities
```python
agent_body = {
"@odata.type": "Microsoft.Graph.AgentIdentity",
"displayName": "my-agent-instance-1",
"agentIdentityBlueprintId": app_id,
"[email protected]": [
f"https://graph.microsoft.com/beta/users/{user_id}"
],
}
resp = requests.post(f"{GRAPH}/servicePrincipals", headers=headers, json=agent_body)
resp.raise_for_status()
agent = resp.json()
```
## API Reference
| Operation | Method | Endpoint | OData Type |
|-----------|--------|----------|------------|
| Create Blueprint | `POST` | `/applications` | `Microsoft.Graph.AgentIdentityBlueprint` |
| Create BlueprintPrincipal | `POST` | `/servicePrincipals` | `Microsoft.Graph.AgentIdentityBlueprintPrincipal` |
| Create Agent Identity | `POST` | `/servicePrincipals` | `Microsoft.Graph.AgentIdentity` |
| List Agent Identities | `GET` | `/servicePrincipals?$filter=...` | — |
| Delete Agent Identity | `DELETE` | `/servicePrincipals/{id}` | — |
| Delete Blueprint | `DELETE` | `/applications/{id}` | — |
All endpoints use base URL: `https://graph.microsoft.com/beta`
## Required Permissions
| Permission | Purpose |
|-----------|---------|
| `Application.ReadWrite.All` | Blueprint CRUD (application objects) |
| `AgentIdentityBlueprint.Create` | Create new Blueprints |
| `AgentIdentityBlueprint.ReadWrite.All` | Read/update Blueprints |
| `AgentIdentityBlueprintPrincipal.Create` | Create BlueprintPrincipals |
| `AgentIdentity.Create.All` | Create Agent Identities |
| `AgentIdentity.ReadWrite.All` | Read/update Agent Identities |
There are **18 Agent Identity-specific** Graph application permissions. Discover all:
```bash
az ad sp show --id 00000003-0000-0000-c000-000000000000 \
--query "appRoles[?contains(value, 'AgentIdentity')].{id:id, value:value}" -o json
```
Grant admin consent (required for application permissions):
```bash
az ad app permission admin-consent --id <client-id>
```
> Admin consent may fail with 404 if the service principal hasn't replicated. Retry with 10–40s backoff.
## Cleanup
```python
# Delete Agent Identity
requests.delete(f"{GRAPH}/servicePrincipals/{agent['id']}", headers=headers)
# Delete BlueprintPrincipal (get SP ID first)
sps = requests.get(
f"{GRAPH}/servicePrincipals?$filter=appId eq '{app_id}'",
headers=headers,
).json()
for sp in sps.get("value", []):
requests.delete(f"{GRAPH}/servicePrincipals/{sp['id']}", headers=headers)
# Delete Blueprint
requests.delete(f"{GRAPH}/applications/{blueprint_obj_id}", headers=headers)
```
## Best Practices
1. **Always create BlueprintPrincipal after Blueprint** — not auto-created; implement idempotent checks on both
2. **Use User objects as sponsors** — ServicePrincipals and Groups are rejected
3. **Handle permission propagation delays** — after admin consent, wait 30–120s; retry with backoff on 403
4. **Include `OData-Version: 4.0` header** on every Graph request
5. **Use Workload Identity Federation for production auth** — for local dev, use a client secret on the Blueprint (see [references/oauth2-token-flow.md](references/oauth2-token-flow.md))
6. **Set `identifierUris` on Blueprint** before using OAuth2 scoping (`api://{app-id}`)
7. **Never use Azure CLI tokens** for API calls — they contain `Directory.AccessAsUser.All` which is hard-rejected
8. **Check for existing resources** before creating — implement idempotent provisioning
## References
| File | Contents |
|------|----------|
| [references/oauth2-token-flow.md](references/oauth2-token-flow.md) | Production (Managed Identity + WIF) and local dev (client secret) token flows |
| [references/known-limitations.md](references/known-limitations.md) | 29 known issues organized by category (from official preview known-issues page) |
| [references/sdk-sidecar.md](references/sdk-sidecar.md) | Microsoft Entra SDK for AgentID — endpoints, 3P agent patterns, Docker/K8s deployment, security |
### External Links
| Resource | URL |
|----------|-----|
| Official Setup Guide | https://learn.microsoft.com/en-us/entra/agent-id/identity-platform/agent-id-setup-instructions |
| AI-Guided Setup | https://learn.microsoft.com/en-us/entra/agent-id/identity-platform/agent-id-ai-guided-setup |
| Microsoft Entra SDK for AgentID — Overview | https://learn.microsoft.com/en-us/entra/msidweb/agent-id-sdk/overview |
| Microsoft Entra SDK for AgentID — Endpoints | https://learn.microsoft.com/en-us/entra/msidweb/agent-id-sdk/endpoints |
Tous les fichiers
0 fichiersInstaller entra-agent-id
Téléchargez et décompressez les fichiers de compétences dans votre répertoire .claude/skills/.
Télécharger le ZIPClonez le dépôt et copiez les fichiers de compétence dans votre projet.
git clone https://github.com/microsoft/skills/tree/main/.github/skills/entra-agent-id # Copy SKILL.md to your .claude/skills/ directory
Copier





Maison
