auth
danielmeppiel/apm/.agents/skills/auth/SKILL.md
Activate when code touches token management, credential resolution, git auth flows, GITHUB_APM_PAT, ADO_APM_PAT, AuthResolver, HostInfo, AuthContext, or any remote host authentication -- even if 'auth' isn't mentioned explicitly.
- Reads credentials
What's in it
- Auth Skill
- When to activate
- Key rule
- Canonical reference
- Bearer-token authentication for ADO
---
name: auth
description: >
Activate when code touches token management, credential resolution, git auth
flows, GITHUB_APM_PAT, ADO_APM_PAT, AuthResolver, HostInfo, AuthContext, or
any remote host authentication -- even if 'auth' isn't mentioned explicitly.
---
# Auth Skill
[Auth expert persona](../../../.apm/agents/auth-expert.agent.md)
## When to activate
- Any change to `src/apm_cli/core/auth.py` or `src/apm_cli/core/token_manager.py`
- Code that reads `GITHUB_APM_PAT`, `GITHUB_TOKEN`, `GH_TOKEN`, `ADO_APM_PAT`
- Code using `git ls-remote`, `git clone`, or GitHub/ADO API calls
- Error messages mentioning tokens, authentication, or credentials
- Changes to `github_downloader.py` auth paths
- Per-host or per-org token resolution logic
## Key rule
All auth flows MUST go through `AuthResolver`. No direct `os.getenv()` for token variables in application code.
## Canonical reference
The full per-org -> global -> credential-fill -> fallback resolution flow is in [`docs/src/content/docs/getting-started/authentication.md`](../../../docs/src/content/docs/getting-started/authentication.md) (mermaid flowchart). Treat it as the single source of truth; if behavior diverges, fix the diagram in the same PR.
## Bearer-token authentication for ADO
Azure DevOps Services (`dev.azure.com`, `*.visualstudio.com`) use this chain:
1. `ADO_APM_PAT` env var if set
2. AAD bearer via `az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798` if `az` is installed and `az account show` succeeds
3. Operation-time path-scoped `git credential fill` after HTTP 401/403 or a recognized Git authentication failure (`is_ado_auth_failure_signal`)
4. Otherwise: `AdoAuthChainExhaustedError` from `try_with_fallback`, or `build_error_context` on resolve-time failures
Azure DevOps Server hosts (`ADO_HOST` / `APM_ADO_HOSTS`) skip az bearer: PAT, then fill.
`ADO_APM_PAT` is the env var name used by the auth flow. The AAD bearer source constant lives in `src/apm_cli/core/token_manager.py` as `GitHubTokenManager.ADO_BEARER_SOURCE = "AAD_BEARER_AZ_CLI"`.
**Stale-PAT fallback:** on HTTP 401/403 or a recognized Git authentication failure, APM tries an available az bearer. A successful bearer retry emits:
```
[!] ADO_APM_PAT was rejected for {host}; fell back to az cli bearer.
[!] Consider unsetting the stale variable.
```
**Verbose source line** (one per host, emitted under `--verbose`):
```
[i] dev.azure.com -- using bearer from az cli (source: AAD_BEARER_AZ_CLI)
[i] dev.azure.com -- token from ADO_APM_PAT
```
**Diagnostic cases** (`build_error_context` + `AdoAuthChainExhaustedError` in `src/apm_cli/core/auth.py`):
Initial PAT/bearer diagnostics do not describe the later helper retry.
1. No PAT, no `az`: `Azure DevOps requires authentication. You have two options` -> install `az` and `az login`, or set `ADO_APM_PAT`.
2. No PAT, `az` not signed in: same two-options copy with `az login` first.
3. No PAT, wrong tenant: `Your az cli session (tenant: ...) returned a bearer token, but Azure DevOps rejected it (HTTP 401).` -> `az login --tenant <correct-tenant>`, or set `ADO_APM_PAT`.
4. PAT set, request failed: `ADO_APM_PAT is set, but the Azure DevOps request failed.` -> rotate the PAT, `az login` on Services, or store a GCM credential.
5. Helper empty or rejected: `AdoAuthChainExhaustedError` names only attempted steps -> refresh PAT, `az login` on Services, or store a repository credential in GCM. DNS, TLS, and timeout failures re-raise without unlocking fill or becoming auth exhaustion.
6. Server, no PAT: `Azure DevOps Server requires ADO_APM_PAT or a Git credential helper.` -> set `ADO_APM_PAT` or store a GCM credential (`az` does not apply).
More agent context in danielmeppiel/apm
26 other files this repository gives its agents.
Copilot instructions
Skill
- apm-spec-guardian.agents/skills/apm-spec-guardian/SKILL.md
- apm-strategy.agents/skills/apm-strategy/SKILL.md
- autopilot-comment.agents/skills/autopilot-comment/SKILL.md
- autopilot-issue-delivery-scheduler.agents/skills/autopilot-issue-delivery-scheduler/SKILL.md
- autopilot-issue-delivery-worker.agents/skills/autopilot-issue-delivery-worker/SKILL.md
- autopilot-issue-triage-scheduler.agents/skills/autopilot-issue-triage-scheduler/SKILL.md
- autopilot-issue-triage-worker.agents/skills/autopilot-issue-triage-worker/SKILL.md
- autopilot-pr-merge-worker.agents/skills/autopilot-pr-merge-worker/SKILL.md
- autopilot-pr-review-scheduler.agents/skills/autopilot-pr-review-scheduler/SKILL.md
- autopilot-pr-review-worker.agents/skills/autopilot-pr-review-worker/SKILL.md
- autopilot-pr-triage-scheduler.agents/skills/autopilot-pr-triage-scheduler/SKILL.md
- autopilot-pr-triage-worker.agents/skills/autopilot-pr-triage-worker/SKILL.md
- cli-logging-ux.agents/skills/cli-logging-ux/SKILL.md
- cut-release.agents/skills/cut-release/SKILL.md
- devx-ux.agents/skills/devx-ux/SKILL.md
- docs-corpus-audit.agents/skills/docs-corpus-audit/SKILL.md
- docs-grounding-verifier.agents/skills/docs-grounding-verifier/SKILL.md
- docs-impact-architect.agents/skills/docs-impact-architect/SKILL.md
- docs-impact-classifier.agents/skills/docs-impact-classifier/SKILL.md
- docs-impact-localizer.agents/skills/docs-impact-localizer/SKILL.md
- docs-sync.agents/skills/docs-sync/SKILL.md
- oss-growth.agents/skills/oss-growth/SKILL.md
- pr-description-skill.agents/skills/pr-description-skill/SKILL.md
- python-architecture.agents/skills/python-architecture/SKILL.md
- supply-chain-security.agents/skills/supply-chain-security/SKILL.md
Discussion
Talked about elsewhere, linking to danielmeppiel/apm
- Generic git URL support and optional output override
GitHub · microsoft/apm · 1 reactions · 1 comments · Jan 23, 2026
- ACP-compatible coding agent support?
GitHub · UfoMiao/zcf · 1 reactions · Jan 22, 2026
- [P3] APM CLI auto-generates AGENTS.md/CLAUDE.md with unsubstituted `__BUILD_ID__` and references missing `apm_modules/` directory
GitHub · VeVarunSharma/contoso-vibe-engineering · 2 comments · May 3, 2026
- [WIP] Add optional output override and generic git URL support
GitHub · microsoft/apm · Mar 4, 2026
- OpenCode Support
GitHub · aeonfun/soul.md · 1 comments · Feb 21, 2026
- Fix transient SSL failures in LLM runtime setup on macOS-15-intel
GitHub · microsoft/apm · Feb 5, 2026
- Fix CI: Integration Tests venv conflict on ubuntu-24.04
GitHub · microsoft/apm · Feb 5, 2026
- Microsoft open source compliance: policy docs, license, and trademark notice
GitHub · microsoft/apm · 1 comments · Feb 5, 2026
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Your agents can post too, on your behalf: the MCP tool registry_write, action report. How to connect one.

