|
| 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 | +### OAuth Client Credentials |
| 90 | + |
| 91 | +Most commands use OAuth client credentials authentication: |
| 92 | + |
| 93 | +```bash |
| 94 | +export SFCC_CLIENT_ID=my-client |
| 95 | +export SFCC_CLIENT_SECRET=my-secret |
| 96 | +``` |
| 97 | + |
| 98 | +Required for: |
| 99 | +- Code management (`code list`, `code activate`, `code delete`) |
| 100 | +- Job operations (`job run`, `job search`, `job import`, `job export`) |
| 101 | +- Site operations (`sites list`) |
| 102 | +- ODS operations |
| 103 | +- SLAS operations |
| 104 | +- MRT operations |
| 105 | + |
| 106 | +### Basic Auth (WebDAV) |
| 107 | + |
| 108 | +WebDAV operations support Basic Auth for better performance: |
| 109 | + |
| 110 | +```bash |
| 111 | +export SFCC_USERNAME=my-user |
| 112 | +export SFCC_PASSWORD=my-access-key |
| 113 | +``` |
| 114 | + |
| 115 | +Used by: |
| 116 | +- `code deploy` (file upload) |
| 117 | +- `code watch` (file upload) |
| 118 | +- `webdav` commands |
| 119 | + |
| 120 | +### Mixed Authentication |
| 121 | + |
| 122 | +Some commands (like `code deploy`) require both OAuth and WebDAV access. You can provide both: |
| 123 | + |
| 124 | +```bash |
| 125 | +export SFCC_CLIENT_ID=my-client |
| 126 | +export SFCC_CLIENT_SECRET=my-secret |
| 127 | +export SFCC_USERNAME=my-user |
| 128 | +export SFCC_PASSWORD=my-access-key |
| 129 | +b2c code deploy --reload |
| 130 | +``` |
| 131 | + |
| 132 | +### Configuration File |
| 133 | + |
| 134 | +Credentials can also be stored in a `dw.json` file: |
| 135 | + |
| 136 | +```json |
| 137 | +{ |
| 138 | + "client-id": "my-client", |
| 139 | + "client-secret": "my-secret", |
| 140 | + "username": "my-user", |
| 141 | + "password": "my-access-key" |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +Use `--config` to specify a custom config file path, or `--instance` to select a named instance configuration. |
0 commit comments