microsoft/skills

azure-identity-pymicrosoft/skills

选对Python凭证类型,并正确管理token与客户端生命周期

  • SKILL.md 已保存
  • 中文用法已整理
  • 安装与运行未实测
先判断是否解决你的问题

azure-identity-py 是什么?

azure-identity-py 处理Python Azure SDK的Entra ID认证,覆盖本地凭证链、托管/工作负载身份、服务主体、设备码和直接取token。它特别说明Python证书类型叫CertificateCredential,并要求同步/异步客户端和凭证保持一致、关闭传输资源。

中文说明由本站依据来源整理;英文原文保留在页面下方。

同名项目,请核对仓库和目录

按客户端选择安装入口

怎么接入你的 Agent?

  1. 定位完整 Skill 目录

    打开本项目来源,核对 SKILL.md 及其引用的脚本和资料。

  2. 交给你正在用的 Agent

    在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。

  3. 确认识别,再做具体任务

    让 Agent 回报安装目录和识别到的名称 azure-identity-py,然后按本页使用示例提供材料。

展开并复制给 Codex 的安装指令
发送给 Codex

安装并检查 azure-identity-py

请在 Codex 的当前工作环境中安装并检查 azure-identity-py 这个 Skill。

项目身份:microsoft/skills / azure-identity-py
来源:https://github.com/microsoft/skills/blob/f03ec5392f7a0f3aca12af47477e92f1edf7b44c/.github/plugins/azure-sdk-python/skills/azure-identity-py/SKILL.md
已定位的源文件:.github/plugins/azure-sdk-python/skills/azure-identity-py/SKILL.md

1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。
准备输入,再按步骤执行

装好以后,具体怎么用?

准备哪些材料

  • 工程使用兼容Python和azure-identity版本,明确目标服务scope与运行环境;本地CLI登录、生产托管身份、CI服务主体分别准备真实配置。可选broker或持久缓存功能按实际环境决定。

会得到什么

  • 环境、服务scope与同步模式明确的Python认证代码,以及真实认证/权限检查状态和缺项。

实际使用顺序

  1. 本地按需要用DefaultAzureCredential;云端优先明确的ManagedIdentity/WorkloadIdentity凭证,或按支持版本限制AZURE_TOKEN_CREDENTIALS。用户分配身份与租户scope要核对,不默默允许任意租户。
  2. 服务主体证书用CertificateCredential,不用Java/C#里同名近似类。OpenAI等非Azure SDK调用可用get_bearer_token_provider并传正确服务scope,不手工长期保存access token。
  3. 同步使用azure.identity和同步client并用with;异步改用azure.identity.aio及对应aio服务client,凭证和客户端都用async with。认证失败时区分无法尝试凭证与尝试后失败,并核对当前链条和身份来源。
  4. 需要持久token缓存时明确启用TokenCachePersistenceOptions并核对系统安全存储;不把允许未加密fallback当生产默认。检查日志只展示必要诊断,不暴露凭证内容。
使用示例

从一个具体任务开始

本站根据源文件编写的使用示例,未在本站实际运行。示例中的文件由你提供。

安装并识别 Skill 后发送

复制一个具体任务

教学任务:用azure-identity-py审查我的异步Blob读取代码。请核对是否同时用了aio凭证和aio客户端,补async with关闭生命周期,并区分本地DefaultAzureCredential与生产托管身份。只审代码和配置,不获取token或读Blob;如用证书说明Python正确类名。
预期结果

预期得到一致的异步资源管理与凭证选择修改建议;本站未运行Python认证或存储调用。

使用前先看这些限制

使用条件与边界

  • 成功获取management scope的token不证明具有Blob等数据面的权限或使用了正确service scope。
  • 凭证链选项、Python最低版本与identity包支持会变化,示范必须与实际安装版本核对。
针对这个 Skill 的疑问

常见问题

Python为什么找不到ClientCertificateCredential?

绑定源明确指出Python类名是CertificateCredential;其他语言SDK名称不能直接搬过来。还要核对使用的是同步包还是azure.identity.aio异步包。

异步函数能混用同步client吗?

该源要求一条调用链选定同步或异步模式。异步路线使用aio凭证和aio服务client,并用async with释放资源,不能只在外层加async就认为全部调用已非阻塞。

需要核对时再展开原文

来源原文与资料状态

源文件
已保存 SKILL.md,抓取于 2026-11-16T12:36:35.145Z
中文使用说明
已针对下方源文件版本整理用途、用法和常见问题
安装与任务测试
本站未执行安装或任务测试
来源复核
本页中文用法已对照保存版本的完整 SKILL.md 阅读整理
展开 SKILL.md 原文、章节与历史收录资料

.github/plugins/azure-sdk-python/skills/azure-identity-py/SKILL.md · 抓取时间 2026-11-16T12:36:35.145Z

以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。

抓取成功不代表已完成安装或任务测试。

来源 description(原文)

Azure Identity SDK for Python authentication with Microsoft Entra ID. Use for DefaultAzureCredential, managed identity, service principals, and token caching. Triggers: "azure-identity", "DefaultAzureCredential", "authentication", "managed identity", "service principal", "credential".

查看源文件章节 / Source sections
  • 原文:Azure Identity library for Python
  • 安装 / Installation
  • 原文:Python Version
  • 原文:Environment Variables
  • 原文:Authentication & Lifecycle
  • 原文:DefaultAzureCredential
  • 原文:Credential Chain Order
  • 原文:Customizing DefaultAzureCredential
  • 原文:Exclude Parameters
  • 原文:get_bearer_token_provider
  • 原文:Credential Types
  • 原文:Credential Chains
  • 原文:Azure-Hosted Applications
  • 原文:Service Principals
  • 原文:User Authentication
  • 原文:Developer Tools
  • 原文:Specific Credential Examples
  • 原文:ManagedIdentityCredential
  • 原文:ClientSecretCredential
  • 原文:CertificateCredential
  • 原文:AzureCliCredential
  • 原文:ChainedTokenCredential
  • 原文:WorkloadIdentityCredential
  • 原文:DeviceCodeCredential
  • 原文:InteractiveBrowserCredential
  • 原文:OnBehalfOfCredential
  • 原文:AzurePipelinesCredential
  • 原文:Getting Tokens Directly
  • 原文:Async Credentials
  • 原文:Sovereign Clouds
原文:Azure Identity library for Python

Authentication library for Azure SDK clients using Microsoft Entra ID. Use this skill when: - An app needs to authenticate to Azure services from Python - You need `DefaultAzureCredential` for local dev + Azure deployment - You need `ManagedIdentityCredential` for Azure-hosted workloads - You need service principal auth with secret or certificate - You need direct token acquisition with `get_token()` - You need to troubleshoot credential chain failures

安装 / Installation

```bash pip install azure-identity ``` For VS Code or broker-based desktop auth: ```bash pip install azure-identity-broker ```

原文:Python Version

`azure-identity` supports Python 3.9+.

原文:Environment Variables

```bash # Service principal with client secret AZURE_TENANT_ID=<your-tenant-id> AZURE_CLIENT_ID=<your-client-id> AZURE_CLIENT_SECRET=<your-client-secret> # Service principal with certificate AZURE_TENANT_ID=<your-tenant-id> AZURE_CLIENT_ID=<your-client-id> AZURE_CLIENT_CERTIFICATE_PATH=/path/to/cert.pem AZURE_CLIENT_CERTIFICATE_PASSWORD=<optional-password> # Authority (sovereign clouds) AZURE_AUTHORITY_HOST=login.microsoftonline.com # Default; or login.chinacloudapi.cn, login.microsoftonline.us # User-assigned managed identity AZURE_CLIENT_ID=<managed-identity-client-id> # Credential selection (new) AZURE_TOKEN_CREDENTIALS=dev|prod|<credential-name> # Optional, restricts DAC chain ```

原文:Authentication & Lifecycle

> **🔑 Two rules apply to every code sample below:** > > 1. **Prefer `DefaultAzureCredential`.** It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation. > - Local dev: `DefaultAzureCredential` works as-is. > - Production: set `AZURE_TOKEN_CREDENTIALS=prod` (or `AZURE_TOKEN_CREDENTIALS=<specific_credential>`) to constrain the credential chain to production-safe credentials. > 2. **Wrap credentials and clients in context managers** when they own token caches / transports: > - Sync: `with DefaultAzureCredential() as credential:` > - Async: `async with DefaultAzureCredential() as credential:` (from `azure.identity.aio`) > > Snippets may abbreviate this setup, but production code should always follow both rules.

原文:DefaultAzureCredential

The recommended credential for most scenarios. Tries multiple authentication methods in order: ```python from azure.identity import DefaultAzureCredential from azure.storage.blob import BlobServiceClient # Works in local dev AND production without code changes credential = DefaultAzureCredential() with BlobServiceClient( account_url="https://<account>.blob.core.windows.net", credential=credential ) as client: containers = list(client.list_containers()) ```

文件 SHA256:b10709c8cadc23134bfee415010f9f0292e39f06c216df3f3dd6fc826897414c

仓库许可证记录:MIT;skill-declaration-captured-not-interpreted,查看来源。

SKILL.md原文description · 2026-11-16T12:36:35.145Z

Azure Identity SDK for Python authentication with Microsoft Entra ID. Use for DefaultAzureCredential, managed identity, service principals, and token caching. Triggers: "azure-identity", "DefaultAzureCredential", "authentication", "managed identity", "service principal", "credential".

查看历史简介来源

历史收录数据

来源仓库microsoft/skills
Skill源路径.github/plugins/azure-sdk-python/skills/azure-identity-py/SKILL.md

安装前请让使用的Agent先读取这个SKILL.md及其所在目录,确认依赖和所需权限。此页不生成未经来源验证的安装命令。

返回 Skills 目录,按任务继续筛选 · MCP与Skills教程与资源