Authentication
SpecFact CLI supports device code authentication flows for GitHub and Azure DevOps to keep credentials out of scripts and CI logs.
Quick Start
GitHub (Device Code)
specfact auth github
Use a custom OAuth client or GitHub Enterprise host:
specfact auth github --client-id YOUR_CLIENT_ID
specfact auth github --base-url https://github.example.com
Note: The default client ID ships with the CLI and is only valid for https://github.com. For GitHub Enterprise, you must supply your own client ID via --client-id or SPECFACT_GITHUB_CLIENT_ID.
Azure DevOps (Device Code)
specfact auth azure-devops
Note: OAuth tokens expire after approximately 1 hour. For longer-lived authentication, use a Personal Access Token (PAT) with up to 1 year expiration:
# Store PAT token (recommended for automation)
specfact auth azure-devops --pat your_pat_token
Azure DevOps Token Resolution Priority
When using Azure DevOps commands (e.g., specfact backlog refine ado, specfact backlog map-fields), tokens are resolved in this priority order:
- Explicit token parameter:
--ado-tokenCLI flag - Environment variable:
AZURE_DEVOPS_TOKEN - Stored token: Token stored via
specfact auth azure-devops(checked automatically) - Expired stored token: If stored token is expired, a warning is shown with options to refresh
Example:
# Uses stored token automatically (no need to specify)
specfact backlog refine ado --ado-org myorg --ado-project myproject
# Override with explicit token
specfact backlog refine ado --ado-org myorg --ado-project myproject --ado-token your_token
# Use environment variable
export AZURE_DEVOPS_TOKEN=your_token
specfact backlog refine ado --ado-org myorg --ado-project myproject
Token Types:
- OAuth Tokens: Device code flow, expire after ~1 hour, automatically refreshed when possible
- PAT Tokens: Personal Access Tokens, can last up to 1 year, recommended for automation and CI/CD
Check Status
specfact auth status
Clear Stored Tokens
# Clear one provider
specfact auth clear --provider github
# Clear all providers
specfact auth clear
Token Storage
Tokens are stored locally in:
~/.specfact/tokens.json
On POSIX systems, SpecFact CLI sets restrictive permissions on the token directory and file.
Adapter Token Precedence
Adapters resolve tokens in this order:
- Explicit token parameter (CLI flag or code)
- Environment variable (e.g.,
GITHUB_TOKEN,AZURE_DEVOPS_TOKEN) - Stored auth token (
specfact auth ...) - GitHub CLI (
gh auth token) for GitHub if enabled
Azure DevOps Specific:
For Azure DevOps commands, stored tokens are automatically used by:
specfact backlog refine ado- Automatically uses stored token if availablespecfact backlog map-fields- Automatically uses stored token if available
If a stored token is expired, you’ll see a warning with options to:
- Use a PAT token (recommended for longer expiration)
- Re-authenticate via
specfact auth azure-devops - Use
--ado-tokenoption with a valid token
Troubleshooting
Token Resolution Issues
Problem: “Azure DevOps token required” error even after running specfact auth azure-devops
Solutions:
- Check token expiration: OAuth tokens expire after ~1 hour. Use a PAT token for longer expiration:
specfact auth azure-devops --pat your_pat_token - Use explicit token: Override with
--ado-tokenflag:specfact backlog refine ado --ado-org myorg --ado-project myproject --ado-token your_token - Set environment variable: Use
AZURE_DEVOPS_TOKENenvironment variable:export AZURE_DEVOPS_TOKEN=your_token specfact backlog refine ado --ado-org myorg --ado-project myproject - Re-authenticate: Clear and re-authenticate:
specfact auth clear --provider azure-devops specfact auth azure-devops
For full adapter configuration details, see: