You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|**User Authentication**| When `--user-auth` is passed, or when only a client ID is provided (no secret) | Roles configured on your **user account**|
44
44
|**Client Credentials**| When both `--client-id` and `--client-secret` are provided | Roles configured on the **API client**|
45
+
|**JWT Bearer**| When `--jwt-cert` and `--jwt-key` are provided (certificate-based authentication) | Roles configured on the **API client**|
45
46
|**Stateful User Authentication**| After running `b2c auth login` — browser-based login, token stored and reused | Roles configured on your **user account**|
46
47
|**Stateful Client Authentication**| After running `b2c auth client` — client credentials login, token stored and reused | Roles configured on the **API client**|
47
48
48
49
**User Authentication** opens a browser for interactive login and uses roles assigned to your user account. This is ideal for development and manual operations. Use `--user-auth` as a shorthand for `--auth-methods implicit` on any OAuth command.
49
50
50
51
**Client Credentials** uses the API client's secret for non-interactive authentication. This is ideal for CI/CD pipelines and automation.
51
52
53
+
**JWT Bearer** uses a public/private certificate pair for secure authentication without storing client secrets. This is ideal for production environments and CI/CD where you want stronger security. See [JWT Authentication](#jwt-authentication-certificate-based) for details.
54
+
52
55
**Stateful User Auth** uses `b2c auth login` to open a browser for interactive login once, then stores the session on disk. Subsequent commands automatically use the stored token when it is present and valid, without re-opening the browser. Clear the session with `b2c auth logout`. See [Auth Commands](/cli/auth#b2c-auth-login) for details.
53
56
54
57
**Stateful Client Auth** uses `b2c auth client` to authenticate once with client credentials (or user/password), store the session, and reuse it across subsequent commands without passing credentials each time. Mirrors the [sfcc-ci](https://github.com/SalesforceCommerceCloud/sfcc-ci)`client:auth` workflow. Use `--renew` to enable automatic token renewal via `b2c auth client renew`. See [Auth Commands](/cli/auth#b2c-auth-client) for details.
@@ -75,9 +78,14 @@ For Account Manager operations that require user-level roles (organization and A
75
78
-**Password**: A strong client secret (save this securely for Client Credentials auth)
76
79
5. Configure the **Token Endpoint Auth Method**:
77
80
-`client_secret_basic` for client credentials flow
81
+
-`private_key_jwt` for JWT Bearer authentication (certificate-based)
82
+
83
+
::: tip Certificate-Based Authentication
84
+
For enhanced security, use JWT Bearer authentication instead of client secrets. This requires uploading a certificate to the API client and using the `--jwt-cert` and `--jwt-key` flags. See [JWT Authentication](#jwt-authentication-certificate-based) for setup instructions.
85
+
:::
78
86
79
87
::: warning
80
-
The B2C CLI only supports `client_secret_basic`for the Token Endpoint Auth Method. `client_secret_post`and `private_key_jwt` aren't currently supported.
88
+
For client credentials with secrets, only `client_secret_basic`is supported. `client_secret_post`isn't currently supported.
81
89
:::
82
90
83
91
### Assigning Roles
@@ -150,12 +158,158 @@ For **User Authentication** (implicit flow), configure redirect URLs in your API
150
158
|`http://localhost:8080`| Required for B2C CLI user authentication |
151
159
|`https://admin.dx.commercecloud.salesforce.com/oauth2-redirect.html`| Optional - enables ODS Swagger interface with same client |
152
160
153
-
**Note:** Redirect URLs are not required for API clients using only Client Credentials authentication.
161
+
**Note:** Redirect URLs are not required for API clients using only Client Credentials or JWT Bearer authentication.
154
162
155
163
::: tip Running Behind a Proxy
156
164
If you're running the CLI behind a proxy where `localhost:8080` isn't reachable by the browser, set `SFCC_REDIRECT_URI` to the proxy URL (e.g., `https://proxy.example.com:8080`). The proxy should forward traffic to the CLI's local server. You can also change the local server port with `SFCC_OAUTH_LOCAL_PORT`. Make sure to add your proxy URL to the API client's redirect URLs in Account Manager.
157
165
:::
158
166
167
+
## JWT Authentication (Certificate-Based)
168
+
169
+
JWT Bearer authentication (RFC 7523) provides a more secure alternative to client secrets by using public/private certificate pairs. This is ideal for production environments and CI/CD pipelines where you want to avoid storing sensitive secrets.
170
+
171
+
### How It Works
172
+
173
+
1. You generate a certificate pair (public certificate + private key)
174
+
2. You register the **public certificate** in Account Manager
175
+
3. The CLI uses the **private key** to sign JWT tokens for authentication
176
+
4. Account Manager verifies the signature using your registered certificate
177
+
178
+
### Benefits
179
+
180
+
-**More secure**: Private key never leaves your machine
181
+
-**No secrets to leak**: No client secret to store or compromise
182
+
-**Better for CI/CD**: Certificates can be rotated without updating secrets across pipelines
-`cert.pem` - Public certificate (upload to Account Manager)
202
+
-`key.pem` - Private key (keep secure on your machine)
203
+
204
+
::: tip Encrypted Keys
205
+
For additional security, generate an encrypted private key by omitting `-nodes` and adding a passphrase when prompted. You'll provide the passphrase via `--jwt-passphrase` when using the CLI.
206
+
:::
207
+
208
+
#### Step 2: Register Certificate in Account Manager
209
+
210
+
1. Log in to [Account Manager](https://account.demandware.com)
211
+
2. Navigate to **API Client** and select your client
212
+
3. Set **Token Endpoint Auth Method** to `private_key_jwt`
213
+
4. Upload `cert.pem` in the **Certificates** section
214
+
5. Save changes
215
+
216
+
::: tip Multiple Certificates per Client
217
+
You can register **multiple certificates** for the same API client. This is useful for:
218
+
-**Team collaboration**: Each developer generates their own key pair and registers their certificate
219
+
-**Key rotation**: Add a new certificate before removing the old one (zero downtime)
220
+
-**Multi-environment**: Different certificates for CI/CD, staging, production
221
+
222
+
Account Manager will verify JWT signatures against all registered certificates, so each team member can authenticate with their own private key while sharing the same client ID.
223
+
:::
224
+
225
+
#### Step 3: Configure CLI
226
+
227
+
You can provide JWT credentials via CLI flags, environment variables, or configuration files.
228
+
229
+
**Using CLI flags:**
230
+
231
+
```bash
232
+
b2c code list \
233
+
--client-id your-client-id \
234
+
--jwt-cert ./cert.pem \
235
+
--jwt-key ./key.pem
236
+
```
237
+
238
+
**Using environment variables:**
239
+
240
+
```bash
241
+
export SFCC_CLIENT_ID=your-client-id
242
+
export SFCC_JWT_CERT=/path/to/cert.pem
243
+
export SFCC_JWT_KEY=/path/to/key.pem
244
+
245
+
b2c code list
246
+
```
247
+
248
+
**Using dw.json:**
249
+
250
+
```json
251
+
{
252
+
"hostname": "your-instance.demandware.net",
253
+
"client-id": "your-client-id",
254
+
"jwt-cert-path": "./cert.pem",
255
+
"jwt-key-path": "./key.pem"
256
+
}
257
+
```
258
+
259
+
**For encrypted keys:**
260
+
261
+
```bash
262
+
b2c code list \
263
+
--client-id your-client-id \
264
+
--jwt-cert ./cert.pem \
265
+
--jwt-key ./key.pem \
266
+
--jwt-passphrase "your-passphrase"
267
+
268
+
# Or via environment variable
269
+
export SFCC_JWT_PASSPHRASE=your-passphrase
270
+
```
271
+
272
+
### Authentication Priority
273
+
274
+
JWT authentication is tried **after** client credentials (if client secret is available) but **before** implicit flow:
275
+
276
+
1.`client-credentials` - Uses client secret if available
277
+
2.`jwt` - Uses JWT certificate if configured (no client secret)
278
+
3.`implicit` - Opens browser for user authentication
279
+
280
+
To force JWT authentication even when a client secret is configured:
281
+
282
+
```bash
283
+
b2c code list --auth-methods jwt
284
+
```
285
+
286
+
### Troubleshooting
287
+
288
+
**"JWT certificate file not found"**
289
+
- Verify the certificate path is correct
290
+
- Use absolute paths or paths relative to current directory
291
+
292
+
**"Invalid JWT private key"**
293
+
- Check that the key file is in PEM format
294
+
- If encrypted, ensure you provide the correct passphrase via `--jwt-passphrase`
295
+
296
+
**"JWT authentication failed (401)"**
297
+
- Verify the certificate is registered in Account Manager
298
+
- Ensure the Token Endpoint Auth Method is set to `private_key_jwt`
299
+
- Check that the client ID matches the API client with the registered certificate
300
+
301
+
**"Invalid certificate format"**
302
+
- The certificate must be in PEM format (starts with `-----BEGIN CERTIFICATE-----`)
303
+
- Regenerate the certificate using the OpenSSL command above
304
+
305
+
### Security Best Practices
306
+
307
+
-**Keep private keys secure**: Never commit `key.pem` to version control
308
+
-**Add to .gitignore**: Include `*.pem` and `*.key` in your `.gitignore`
309
+
-**Use encrypted keys in production**: Generate keys with passphrases for production use
310
+
-**Rotate certificates regularly**: Generate new certificates periodically (every 90-365 days)
311
+
-**Store passphrases securely**: Use secret managers for passphrases in CI/CD
312
+
159
313
## OCAPI Configuration
160
314
161
315
For operations that interact with B2C Commerce instances (code deployment, jobs, sites), you need to configure OCAPI permissions on each instance.
Copy file name to clipboardExpand all lines: docs/guide/configuration.md
+37-3Lines changed: 37 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,9 +16,9 @@ For detailed setup instructions including Account Manager API client creation, r
16
16
17
17
OAuth is required for API operations (code list/activate/delete, jobs, sites, SCAPI commands, SLAS, ODS) and can also be used for WebDAV file operations when basic auth credentials are not provided.
18
18
19
-
#### Client Credentials (Recommended)
19
+
#### Client Credentials
20
20
21
-
OAuth client credentials is the recommended method for production and CI/CD use:
21
+
OAuth client credentials uses a client ID and secret for non-interactive authentication:
22
22
23
23
```bash
24
24
b2c code deploy \
@@ -27,6 +27,20 @@ b2c code deploy \
27
27
--client-secret your-client-secret
28
28
```
29
29
30
+
#### JWT Bearer
31
+
32
+
JWT Bearer uses certificate-based authentication for enhanced security without storing client secrets:
For projects that work with multiple instances, use the `configs` array:
@@ -219,6 +248,9 @@ For the full command reference with all flags, see [Setup Commands](/cli/setup).
219
248
|`code-version`| Code version for deployments |
220
249
|`client-id`| OAuth client ID |
221
250
|`client-secret`| OAuth client secret |
251
+
|`jwt-cert-path`| Path to JWT certificate file (cert.pem) for JWT Bearer authentication. Also accepts `jwtCertPath`. |
252
+
|`jwt-key-path`| Path to JWT private key file (key.pem) for JWT Bearer authentication. Also accepts `jwtKeyPath`. |
253
+
|`jwt-passphrase`| Passphrase for encrypted JWT private key. Also accepts `jwtPassphrase`. |
222
254
|`username`| Basic auth username (WebDAV) |
223
255
|`password`| Basic auth access key (WebDAV) |
224
256
|`oauth-scopes`| OAuth scopes (array of strings) |
@@ -324,7 +356,8 @@ Plugins can add custom configuration sources like secret managers or environment
324
356
325
357
To prevent mixing credentials from different sources, certain fields are treated as atomic groups:
326
358
327
-
-**OAuth**: `clientId` and `clientSecret`
359
+
-**OAuth Client Credentials**: `clientId` and `clientSecret`
360
+
-**OAuth JWT Bearer**: `clientId`, `jwtCertPath`, `jwtKeyPath`, and `jwtPassphrase`
328
361
-**Basic Auth**: `username` and `password`
329
362
330
363
If any field in a group is set by a higher-priority source, all fields in that group from lower-priority sources are ignored. This ensures credential pairs always come from the same source.
@@ -368,6 +401,7 @@ For platform-level commands (Sandbox, SLAS, and Account Manager), the CLI includ
368
401
### Available Auth Methods
369
402
370
403
-`client-credentials` - OAuth 2.0 client credentials flow (requires client ID and secret). Used for SCAPI/OCAPI and WebDAV.
404
+
-`jwt` - OAuth 2.0 JWT Bearer flow (requires client ID, certificate, and private key). Used for SCAPI/OCAPI and WebDAV. More secure than client credentials.
371
405
-`implicit` - OAuth 2.0 implicit flow (requires client ID only, opens browser for login). Used for SCAPI/OCAPI and WebDAV.
372
406
-`basic` - Basic authentication with username and access key. Used for WebDAV operations only.
373
407
-`api-key` - API key authentication. Used for MRT commands only.
0 commit comments