|
| 1 | +# Authentication |
| 2 | + |
| 3 | +Specify CLI uses **opt-in authentication** for HTTP requests to catalog |
| 4 | +sources, extension downloads, and release checks. No credentials are |
| 5 | +sent unless you explicitly configure them. |
| 6 | + |
| 7 | +## Configuration |
| 8 | + |
| 9 | +Create `~/.specify/auth.json` to enable authentication: |
| 10 | + |
| 11 | +```json |
| 12 | +{ |
| 13 | + "providers": [ |
| 14 | + { |
| 15 | + "hosts": ["github.com", "api.github.com", "raw.githubusercontent.com", "codeload.github.com"], |
| 16 | + "provider": "github", |
| 17 | + "auth": "bearer", |
| 18 | + "token_env": "GH_TOKEN" |
| 19 | + } |
| 20 | + ] |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +> **Security:** Restrict the file to owner-only access: |
| 25 | +> ```bash |
| 26 | +> chmod 600 ~/.specify/auth.json |
| 27 | +> ``` |
| 28 | +
|
| 29 | +Without this file, all HTTP requests are unauthenticated. |
| 30 | +
|
| 31 | +## Fields |
| 32 | +
|
| 33 | +Each entry in the `providers` array has the following fields: |
| 34 | +
|
| 35 | +| Field | Required | Description | |
| 36 | +|---|---|---| |
| 37 | +| `hosts` | Yes | Array of hostnames this entry applies to. Supports exact hostnames, or a leading `*.` wildcard for subdomains only (for example, `*.visualstudio.com`). `*.visualstudio.com` matches `foo.visualstudio.com`, but not `visualstudio.com`. Other glob patterns such as `*github.com` or `gith?b.com` are not supported. | |
| 38 | +| `provider` | Yes | Built-in provider key: `github` or `azure-devops`. | |
| 39 | +| `auth` | Yes | Auth scheme (see below). | |
| 40 | +| `token` | No | Token value (inline). Use `token_env` instead when possible. | |
| 41 | +| `token_env` | No | Environment variable name to read the token from. | |
| 42 | +
|
| 43 | +For `azure-ad` auth, additional fields are required: |
| 44 | +
|
| 45 | +| Field | Required | Description | |
| 46 | +|---|---|---| |
| 47 | +| `tenant_id` | Yes | Azure AD tenant ID. | |
| 48 | +| `client_id` | Yes | Service principal client ID. | |
| 49 | +| `client_secret_env` | Yes | Environment variable containing the client secret. | |
| 50 | +
|
| 51 | +Either `token` or `token_env` must be set for `bearer` and `basic-pat` schemes. |
| 52 | +
|
| 53 | +## Providers and auth schemes |
| 54 | +
|
| 55 | +### GitHub (`github`) |
| 56 | +
|
| 57 | +| Scheme | Header | Use for | |
| 58 | +|---|---|---| |
| 59 | +| `bearer` | `Authorization: Bearer <token>` | PATs, fine-grained PATs, OAuth tokens, GitHub App tokens | |
| 60 | +
|
| 61 | +**Example — PAT via environment variable:** |
| 62 | +
|
| 63 | +```json |
| 64 | +{ |
| 65 | + "hosts": ["github.com", "api.github.com", "raw.githubusercontent.com", "codeload.github.com"], |
| 66 | + "provider": "github", |
| 67 | + "auth": "bearer", |
| 68 | + "token_env": "GH_TOKEN" |
| 69 | +} |
| 70 | +``` |
| 71 | +
|
| 72 | +### Azure DevOps (`azure-devops`) |
| 73 | + |
| 74 | +| Scheme | Header | Use for | |
| 75 | +|---|---|---| |
| 76 | +| `basic-pat` | `Authorization: Basic base64(:<PAT>)` | Personal Access Tokens | |
| 77 | +| `bearer` | `Authorization: Bearer <token>` | Pre-acquired OAuth / Azure AD tokens | |
| 78 | +| `azure-cli` | `Authorization: Bearer <token>` | Token acquired via `az account get-access-token` | |
| 79 | +| `azure-ad` | `Authorization: Bearer <token>` | Token acquired via OAuth2 client credentials flow | |
| 80 | + |
| 81 | +**Example — PAT via environment variable:** |
| 82 | + |
| 83 | +```json |
| 84 | +{ |
| 85 | + "hosts": ["dev.azure.com"], |
| 86 | + "provider": "azure-devops", |
| 87 | + "auth": "basic-pat", |
| 88 | + "token_env": "AZURE_DEVOPS_PAT" |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +**Example — Azure CLI (interactive login):** |
| 93 | + |
| 94 | +```json |
| 95 | +{ |
| 96 | + "hosts": ["dev.azure.com"], |
| 97 | + "provider": "azure-devops", |
| 98 | + "auth": "azure-cli" |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +Requires `az login` to have been run beforehand. |
| 103 | + |
| 104 | +**Example — Azure AD service principal (CI/automation):** |
| 105 | + |
| 106 | +```json |
| 107 | +{ |
| 108 | + "hosts": ["dev.azure.com"], |
| 109 | + "provider": "azure-devops", |
| 110 | + "auth": "azure-ad", |
| 111 | + "tenant_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 112 | + "client_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 113 | + "client_secret_env": "AZURE_CLIENT_SECRET" |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +## Multiple entries |
| 118 | + |
| 119 | +You can configure multiple entries for different hosts or organizations: |
| 120 | + |
| 121 | +```json |
| 122 | +{ |
| 123 | + "providers": [ |
| 124 | + { |
| 125 | + "hosts": ["github.com", "api.github.com", "raw.githubusercontent.com", "codeload.github.com"], |
| 126 | + "provider": "github", |
| 127 | + "auth": "bearer", |
| 128 | + "token_env": "GH_TOKEN" |
| 129 | + }, |
| 130 | + { |
| 131 | + "hosts": ["dev.azure.com"], |
| 132 | + "provider": "azure-devops", |
| 133 | + "auth": "basic-pat", |
| 134 | + "token_env": "AZURE_DEVOPS_PAT" |
| 135 | + } |
| 136 | + ] |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +## How it works |
| 141 | + |
| 142 | +1. For each outbound HTTP request, the URL hostname is matched against |
| 143 | + the `hosts` patterns in `auth.json`. |
| 144 | +2. If a match is found, the corresponding provider resolves the token |
| 145 | + and attaches the appropriate `Authorization` header. |
| 146 | +3. If the request receives a 401 or 403, the next matching entry is tried. |
| 147 | +4. After all matching entries are exhausted, an unauthenticated request |
| 148 | + is attempted as a final fallback. |
| 149 | +5. On redirects, the `Authorization` header is stripped if the redirect |
| 150 | + target leaves the entry's declared hosts — preventing credential |
| 151 | + leakage to CDNs or third-party services. |
| 152 | + |
| 153 | +## Template |
| 154 | + |
| 155 | +A reference `auth.json` with GitHub pre-configured: |
| 156 | + |
| 157 | +```json |
| 158 | +{ |
| 159 | + "providers": [ |
| 160 | + { |
| 161 | + "hosts": [ |
| 162 | + "github.com", |
| 163 | + "api.github.com", |
| 164 | + "raw.githubusercontent.com", |
| 165 | + "codeload.github.com" |
| 166 | + ], |
| 167 | + "provider": "github", |
| 168 | + "auth": "bearer", |
| 169 | + "token_env": "GH_TOKEN" |
| 170 | + } |
| 171 | + ] |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +To use it: |
| 176 | + |
| 177 | +```bash |
| 178 | +mkdir -p ~/.specify |
| 179 | +# Copy the JSON above into ~/.specify/auth.json |
| 180 | +chmod 600 ~/.specify/auth.json |
| 181 | +``` |
0 commit comments