ado-auth
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseado-auth
ado-auth
Authenticate to Azure DevOps (ADO) and diagnose auth failures. This is a verify and
troubleshoot skill — the bundled already implements both auth
methods, so you are not writing new auth code here. You are confirming a token works
and the org/project point where the user expects, then unblocking the create/query
skills ([[ado-create-work-items]], the orchestrator [[findings-to-ado-backlog]]).
create-backlog.csADO accepts two credential styles. Pick A unless the user has a reason to use a PAT.
完成Azure DevOps(ADO)认证并诊断认证失败问题。这是一项验证与故障排查技能——捆绑的已实现两种认证方式,因此无需在此编写新的认证代码。你需要确认令牌可用,且组织/项目指向用户预期的位置,从而为创建/查询技能([[ado-create-work-items]]、编排器[[findings-to-ado-backlog]])扫清障碍。
create-backlog.csADO支持两种凭证类型。除非用户有明确理由使用PAT,否则优先选择方式A。
Method A — Entra token via Azure CLI (recommended)
方式A — 通过Azure CLI获取Entra令牌(推荐)
Why preferred: no long-lived secret to store, and it rides the user's existing
session. The resource id below is the global Azure DevOps application id (same for
every tenant) — it tells Entra "mint a token for Azure DevOps".
azpowershell
az login
$token = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsvUse it as a bearer header: .
Authorization: Bearer <token>推荐理由:无需存储长期密钥,且可复用用户现有的会话。下方的资源ID是全局Azure DevOps应用ID(所有租户通用)——它告知Entra“为Azure DevOps生成令牌”。
azpowershell
az login
$token = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsv将其用作Bearer头部:。
Authorization: Bearer <token>Method B — Personal Access Token (PAT)
方式B — 个人访问令牌(PAT)
Use when isn't available (e.g. a service context) or the user already has a
PAT. Scope must include Work Items (Read & Write). ADO PATs go in a Basic header
where the username is empty and the password is the PAT:
az loginpowershell
$env:AZDO_PAT = "<your-pat>"
$basic = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$env:AZDO_PAT"))当无法使用(例如服务环境)或用户已拥有PAT时使用。权限范围必须包含工作项(读写)。ADO PAT需放入Basic头部,其中用户名为空,密码为PAT:
az loginpowershell
$env:AZDO_PAT = "<your-pat>"
$basic = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$env:AZDO_PAT"))header -> Authorization: Basic <basic>
header -> Authorization: Basic <basic>
`create-backlog.cs` reads `AZDO_PAT` automatically: if it's set it uses Basic auth,
otherwise it shells out to `az` for an Entra token. So setting (or unsetting)
`AZDO_PAT` is how you switch methods for that script — you don't pass a flag.
`create-backlog.cs`会自动读取`AZDO_PAT`:如果已设置则使用Basic认证,否则会调用`az`获取Entra令牌。因此,设置(或取消设置)`AZDO_PAT`是切换该脚本认证方式的方法——无需传递标志。Verify the credential works
验证凭证是否可用
Run this before kicking off a real create. A against the project endpoint proves
the token is valid and that the user can see the target org/project — the two things
most auth failures actually break. Set to the org name only (not a URL):
200AZDO_ORGpowershell
$env:AZDO_ORG = "Cartagena365" # the NAME, not https://dev.azure.com/...
$env:AZDO_PROJECT = "GlassHull"
$token = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsv
$uri = "https://dev.azure.com/$($env:AZDO_ORG)/_apis/projects/$($env:AZDO_PROJECT)?api-version=7.1"
Invoke-RestMethod -Uri $uri -Headers @{ Authorization = "Bearer $token" }PAT variant — swap the header for:
@{ Authorization = "Basic $([Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$env:AZDO_PAT")))" }A returns the project's JSON (id, name, state). Anything else, see below.
200For a broader prereq sweep (az, .NET 10, python/openpyxl, env vars) run the bundled
checker instead — it's read-only and changes nothing:
powershell
powershell -ExecutionPolicy Bypass -File "${CLAUDE_PLUGIN_ROOT}/scripts/setup_check.ps1"在执行实际创建操作前运行此验证。针对项目端点返回状态码,证明令牌有效且用户可访问目标组织/项目——这是大多数认证失败的两个核心问题。将设置为组织名称(而非URL):
200AZDO_ORGpowershell
$env:AZDO_ORG = "Cartagena365" # 仅填写名称,不要https://dev.azure.com/...
$env:AZDO_PROJECT = "GlassHull"
$token = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsv
$uri = "https://dev.azure.com/$($env:AZDO_ORG)/_apis/projects/$($env:AZDO_PROJECT)?api-version=7.1"
Invoke-RestMethod -Uri $uri -Headers @{ Authorization = "Bearer $token" }PAT变体——将头部替换为:
@{ Authorization = "Basic $([Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$env:AZDO_PAT")))" }返回状态码会得到项目的JSON数据(ID、名称、状态)。若出现其他情况,请查看下方内容。
200如需更全面的前置检查(az、.NET 10、python/openpyxl、环境变量),请运行捆绑的检查脚本——它是只读的,不会更改任何内容:
powershell
powershell -ExecutionPolicy Bypass -File "${CLAUDE_PLUGIN_ROOT}/scripts/setup_check.ps1"Troubleshooting
故障排查
| Symptom | Cause | Fix |
|---|---|---|
| HTTP 401 Unauthorized | No token, or it expired | |
| HTTP 403 Forbidden | Token is valid but lacks rights | PAT scope missing Work Items (Read & Write) — reissue with that scope. For Entra: the account lacks board/project permission — get added to the project / area path. |
| "A potentially dangerous Request.Path value was detected (:)" | | Set |
| 200 but wrong / empty results | Token is fine; you're pointed at the wrong place | Check |
| "could not start az" / "failed to get Entra token" | Azure CLI not installed or no active login | Install Azure CLI (https://aka.ms/installazurecli), run |
| 症状 | 原因 | 修复方法 |
|---|---|---|
| HTTP 401 未授权 | 无令牌或令牌已过期 | 执行 |
| HTTP 403 禁止访问 | 令牌有效但权限不足 | PAT权限范围缺少工作项(读写)——重新生成包含该权限的PAT。对于Entra:账户缺少看板/项目权限——请求添加到项目/区域路径。 |
| "A potentially dangerous Request.Path value was detected (:)" | | 将 |
| 返回200但结果错误/为空 | 令牌正常,但指向错误位置 | 检查 |
| "could not start az" / "failed to get Entra token" | 未安装Azure CLI或无活跃登录 | 安装Azure CLI(https://aka.ms/installazurecli),执行`az login |
Hand-off
交接
Once the verify call returns , auth is good — continue with
[[ado-create-work-items]] (which drives ) or
[[ado-writeback-tracking]]. The same / env vars carry
straight into those steps, so leave them set in this shell. Field shapes and the
/ precedence rules live in .
200create-backlog.csAZDO_ORGAZDO_PROJECTorgprojectreferences/data-contracts.md一旦验证调用返回,说明认证正常——可继续执行[[ado-create-work-items]](调用)或[[ado-writeback-tracking]]。相同的 / 环境变量会直接带入后续步骤,因此请在当前shell中保持其设置。字段格式以及/的优先级规则请查看。
200create-backlog.csAZDO_ORGAZDO_PROJECTorgprojectreferences/data-contracts.md