|
| 1 | +# Auth Commands |
| 2 | + |
| 3 | +Commands for authentication and token management. |
| 4 | + |
| 5 | +## b2c auth token |
| 6 | + |
| 7 | +Get an OAuth access token for use in scripts or other tools. |
| 8 | + |
| 9 | +### Usage |
| 10 | + |
| 11 | +```bash |
| 12 | +b2c auth token |
| 13 | +``` |
| 14 | + |
| 15 | +### Flags |
| 16 | + |
| 17 | +| Flag | Environment Variable | Description | |
| 18 | +|------|---------------------|-------------| |
| 19 | +| `--client-id` | `SFCC_CLIENT_ID` | Client ID for OAuth | |
| 20 | +| `--client-secret` | `SFCC_CLIENT_SECRET` | Client Secret for OAuth | |
| 21 | +| `--scope` | `SFCC_OAUTH_SCOPES` | OAuth scopes to request (can be repeated) | |
| 22 | +| `--account-manager-host` | `SFCC_ACCOUNT_MANAGER_HOST` | Account Manager hostname (default: account.demandware.com) | |
| 23 | + |
| 24 | +### Examples |
| 25 | + |
| 26 | +```bash |
| 27 | +# Get a token with default scopes |
| 28 | +b2c auth token --client-id xxx --client-secret yyy |
| 29 | + |
| 30 | +# Get a token with specific scopes |
| 31 | +b2c auth token --scope sfcc.orders --scope sfcc.products |
| 32 | + |
| 33 | +# Output as JSON (useful for parsing) |
| 34 | +b2c auth token --json |
| 35 | + |
| 36 | +# Using environment variables |
| 37 | +export SFCC_CLIENT_ID=my-client |
| 38 | +export SFCC_CLIENT_SECRET=my-secret |
| 39 | +b2c auth token |
| 40 | +``` |
| 41 | + |
| 42 | +### Output |
| 43 | + |
| 44 | +The command outputs the access token: |
| 45 | + |
| 46 | +``` |
| 47 | +eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9... |
| 48 | +``` |
| 49 | + |
| 50 | +With `--json`: |
| 51 | + |
| 52 | +```json |
| 53 | +{"token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...","expires_in":1799} |
| 54 | +``` |
| 55 | + |
| 56 | +### Use Cases |
| 57 | + |
| 58 | +#### Scripting |
| 59 | + |
| 60 | +Use the token in shell scripts: |
| 61 | + |
| 62 | +```bash |
| 63 | +TOKEN=$(b2c auth token) |
| 64 | +curl -H "Authorization: Bearer $TOKEN" https://my-instance.demandware.net/s/-/dw/data/v24_3/sites |
| 65 | +``` |
| 66 | + |
| 67 | +#### CI/CD Pipelines |
| 68 | + |
| 69 | +Get a token for use with other tools: |
| 70 | + |
| 71 | +```bash |
| 72 | +export SFCC_TOKEN=$(b2c auth token --json | jq -r '.token') |
| 73 | +``` |
| 74 | + |
| 75 | +#### Testing API Calls |
| 76 | + |
| 77 | +Quickly get a token for testing OCAPI or SCAPI: |
| 78 | + |
| 79 | +```bash |
| 80 | +b2c auth token | pbcopy # macOS: copy to clipboard |
| 81 | +``` |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## Authentication Overview |
| 86 | + |
| 87 | +The CLI supports multiple authentication methods depending on the operation. |
| 88 | + |
| 89 | +### Account Manager API Client (OAuth) |
| 90 | + |
| 91 | +Most instance operations require an Account Manager API Client. The CLI supports two authentication methods: |
| 92 | + |
| 93 | +| Auth Method | When Used | Role Configuration | |
| 94 | +|-------------|-----------|-------------------| |
| 95 | +| User Authentication | Only `--client-id` provided | Roles on your **user account** | |
| 96 | +| Client Credentials | Both `--client-id` and `--client-secret` provided | Roles on the **API client** | |
| 97 | + |
| 98 | +```bash |
| 99 | +# User Authentication (opens browser for login) |
| 100 | +b2c ods list --client-id xxx |
| 101 | + |
| 102 | +# Client Credentials |
| 103 | +export SFCC_CLIENT_ID=my-client |
| 104 | +export SFCC_CLIENT_SECRET=my-secret |
| 105 | +b2c ods list |
| 106 | +``` |
| 107 | + |
| 108 | +Used by: |
| 109 | +- Code management (`code list`, `code activate`, `code delete`) |
| 110 | +- Job operations (`job run`, `job search`, `job import`, `job export`) |
| 111 | +- Site operations (`sites list`) |
| 112 | +- ODS operations (requires `Sandbox API User` role) |
| 113 | +- SLAS operations (requires `SLAS Organization Administrator` or `Sandbox API User` role depending on auth method) |
| 114 | + |
| 115 | +### Basic Auth (WebDAV) |
| 116 | + |
| 117 | +WebDAV operations support Basic Auth using your Business Manager username and WebDAV access key: |
| 118 | + |
| 119 | +```bash |
| 120 | +export SFCC_USERNAME=my-user |
| 121 | +export SFCC_PASSWORD=my-webdav-access-key |
| 122 | +``` |
| 123 | + |
| 124 | +Used by: |
| 125 | +- `code deploy` (file upload) |
| 126 | +- `code watch` (file upload) |
| 127 | +- `webdav` commands |
| 128 | + |
| 129 | +### MRT API Key |
| 130 | + |
| 131 | +Managed Runtime commands use a separate API key obtained from the MRT dashboard: |
| 132 | + |
| 133 | +```bash |
| 134 | +export SFCC_MRT_API_KEY=your-mrt-api-key |
| 135 | +``` |
| 136 | + |
| 137 | +See [MRT Commands](./mrt#authentication) for details. |
| 138 | + |
| 139 | +### Mixed Authentication |
| 140 | + |
| 141 | +Some commands (like `code deploy` with `--reload`) require both OAuth and WebDAV access: |
| 142 | + |
| 143 | +```bash |
| 144 | +export SFCC_CLIENT_ID=my-client |
| 145 | +export SFCC_CLIENT_SECRET=my-secret |
| 146 | +export SFCC_USERNAME=my-user |
| 147 | +export SFCC_PASSWORD=my-access-key |
| 148 | +b2c code deploy --reload |
| 149 | +``` |
| 150 | + |
| 151 | +### Configuration File |
| 152 | + |
| 153 | +Credentials can be stored in a `dw.json` file: |
| 154 | + |
| 155 | +```json |
| 156 | +{ |
| 157 | + "client-id": "my-client", |
| 158 | + "client-secret": "my-secret", |
| 159 | + "username": "my-user", |
| 160 | + "password": "my-access-key" |
| 161 | +} |
| 162 | +``` |
| 163 | + |
| 164 | +Use `--config` to specify a custom config file path, or `--instance` to select a named instance configuration. |
| 165 | + |
| 166 | +### Tenant Scope |
| 167 | + |
| 168 | +For ODS and SLAS operations, your API client must have tenant scope configured for the realm/organization you wish to manage. This is set up in Account Manager when creating or editing the API client. |
0 commit comments