Skip to content

Commit 732d4ad

Browse files
Add slas token command for retrieving SLAS shopper access tokens (#232)
Supports public (PKCE) and private (client_credentials) client flows, guest and registered customer authentication, and auto-discovery of public SLAS clients via the admin API. Co-authored-by: amit-kumar8-sf <amit.kumar.sf1408@gmail.com>
1 parent cbd412c commit 732d4ad

File tree

20 files changed

+1476
-18
lines changed

20 files changed

+1476
-18
lines changed

.changeset/slas-token-command.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@salesforce/b2c-cli': minor
3+
'@salesforce/b2c-tooling-sdk': minor
4+
---
5+
6+
Add `slas token` command to retrieve SLAS shopper access tokens for API testing. Supports public (PKCE) and private (client_credentials) client flows, guest and registered customer authentication, and auto-discovery of public SLAS clients.

docs/cli/slas.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,103 @@ For complete setup instructions, see the [Authentication Guide](/guide/authentic
4949

5050
---
5151

52+
## b2c slas token
53+
54+
Get a SLAS shopper access token for testing APIs.
55+
56+
### Usage
57+
58+
```bash
59+
b2c slas token --tenant-id <TENANT_ID> --site-id <SITE_ID>
60+
```
61+
62+
### Flags
63+
64+
| Flag | Environment Variable | Description | Required |
65+
|------|---------------------|-------------|----------|
66+
| `--tenant-id` | `SFCC_TENANT_ID` | SLAS tenant ID (organization ID) | Yes |
67+
| `--site-id` | `SFCC_SITE_ID` | Site/channel ID | Yes* |
68+
| `--slas-client-id` | `SFCC_SLAS_CLIENT_ID` | SLAS client ID (auto-discovered if omitted) | No |
69+
| `--slas-client-secret` | `SFCC_SLAS_CLIENT_SECRET` | SLAS client secret (omit for public clients) | No |
70+
| `--short-code` | `SFCC_SHORTCODE` | SCAPI short code | Yes |
71+
| `--redirect-uri` | | Redirect URI | No |
72+
| `--shopper-login` | | Registered customer login | No |
73+
| `--shopper-password` | | Registered customer password (prompted interactively if omitted) | No |
74+
75+
\* `--site-id` can be auto-discovered from the SLAS client configuration when using auto-discovery.
76+
77+
### Flows
78+
79+
The command automatically selects the appropriate authentication flow:
80+
81+
| Scenario | Flow |
82+
|----------|------|
83+
| No `--slas-client-secret` | Public client PKCE (authorization_code_pkce) |
84+
| With `--slas-client-secret` | Private client (client_credentials) |
85+
| With `--shopper-login` | Registered customer login |
86+
| No `--slas-client-id` | Auto-discovers first public client via SLAS Admin API |
87+
88+
### Examples
89+
90+
```bash
91+
# Guest token with auto-discovery (finds first public SLAS client)
92+
b2c slas token --tenant-id abcd_123 --site-id RefArch
93+
94+
# Guest token with explicit public client (PKCE flow)
95+
b2c slas token --slas-client-id my-client \
96+
--tenant-id abcd_123 --short-code kv7kzm78 --site-id RefArch
97+
98+
# Guest token with private client (client_credentials flow)
99+
b2c slas token --slas-client-id my-client --slas-client-secret sk_xxx \
100+
--tenant-id abcd_123 --short-code kv7kzm78 --site-id RefArch
101+
102+
# Registered customer token
103+
b2c slas token --tenant-id abcd_123 --site-id RefArch \
104+
--shopper-login user@example.com --shopper-password secret
105+
106+
# JSON output (includes refresh token, expiry, usid, etc.)
107+
b2c slas token --tenant-id abcd_123 --site-id RefArch --json
108+
109+
# Use token in a subsequent API call
110+
TOKEN=$(b2c slas token --tenant-id abcd_123 --site-id RefArch)
111+
curl -H "Authorization: Bearer $TOKEN" \
112+
"https://kv7kzm78.api.commercecloud.salesforce.com/..."
113+
```
114+
115+
### Output
116+
117+
- **Normal mode**: prints the raw access token to stdout (pipeable)
118+
- **JSON mode** (`--json`): returns full token details:
119+
120+
```json
121+
{
122+
"accessToken": "...",
123+
"refreshToken": "...",
124+
"expiresIn": 1800,
125+
"tokenType": "Bearer",
126+
"usid": "...",
127+
"customerId": "...",
128+
"clientId": "...",
129+
"siteId": "RefArch",
130+
"isGuest": true
131+
}
132+
```
133+
134+
### Configuration
135+
136+
These values can also be set in `dw.json`:
137+
138+
```json
139+
{
140+
"tenant-id": "abcd_123",
141+
"short-code": "kv7kzm78",
142+
"slas-client-id": "my-public-client",
143+
"site-id": "RefArch"
144+
}
145+
```
146+
147+
---
148+
52149
## b2c slas client list
53150

54151
List SLAS clients for a tenant.

packages/b2c-cli/eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default [
7777
},
7878
},
7979
{
80-
files: ['src/commands/setup/**/*.ts'],
80+
files: ['src/commands/setup/**/*.ts', 'src/commands/slas/**/*.ts'],
8181
rules: {
8282
// ESLint import resolver doesn't understand conditional exports (development condition)
8383
// but Node.js resolves them correctly at runtime

packages/b2c-cli/src/commands/setup/inspect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {withDocs} from '../../i18n/index.js';
1212
/**
1313
* Sensitive fields that should be masked by default.
1414
*/
15-
const SENSITIVE_FIELDS = new Set<keyof NormalizedConfig>(['clientSecret', 'mrtApiKey', 'password']);
15+
const SENSITIVE_FIELDS = new Set<keyof NormalizedConfig>(['clientSecret', 'mrtApiKey', 'password', 'slasClientSecret']);
1616

1717
/**
1818
* JSON output structure for the inspect command.

0 commit comments

Comments
 (0)