Skip to content

Commit 52aa003

Browse files
committed
address comments
1 parent a8950a9 commit 52aa003

2 files changed

Lines changed: 50 additions & 29 deletions

File tree

README.md

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,44 @@ For OAuth Tokens authentication:
195195
- `--refresh-token TEXT`: OAuth refresh token (see [Obtaining Refresh Token](#obtaining-refresh-token-and-core-token))
196196
- `--core-token TEXT`: (Optional) OAuth core/access token - if not provided, it will be obtained using the refresh token
197197

198+
##### Using Environment Variables (Alternative)
199+
200+
Instead of using `datacustomcode configure`, you can also set credentials via environment variables.
201+
202+
> [!NOTE]
203+
> Environment variables take precedence over the credentials INI file when both are present.
204+
205+
**Common (required for all auth types):**
206+
| Variable | Description |
207+
|----------|-------------|
208+
| `SFDC_LOGIN_URL` | Salesforce login URL (e.g., `https://login.salesforce.com`) |
209+
| `SFDC_CLIENT_ID` | External Client App Client ID |
210+
| `SFDC_AUTH_TYPE` | Authentication type: `oauth_tokens` (default) or `username_password` |
211+
212+
**For OAuth Tokens authentication (`SFDC_AUTH_TYPE=oauth_tokens`):**
213+
| Variable | Description |
214+
|----------|-------------|
215+
| `SFDC_CLIENT_SECRET` | External Client App Client Secret |
216+
| `SFDC_REFRESH_TOKEN` | OAuth refresh token |
217+
| `SFDC_CORE_TOKEN` | (Optional) OAuth core/access token |
218+
219+
**For Username/Password authentication (`SFDC_AUTH_TYPE=username_password`):**
220+
| Variable | Description |
221+
|----------|-------------|
222+
| `SFDC_USERNAME` | Salesforce username |
223+
| `SFDC_PASSWORD` | Salesforce password |
224+
| `SFDC_CLIENT_SECRET` | External Client App Client Secret |
225+
226+
Example usage:
227+
```bash
228+
export SFDC_LOGIN_URL="https://login.salesforce.com"
229+
export SFDC_CLIENT_ID="your_client_id"
230+
export SFDC_CLIENT_SECRET="your_client_secret"
231+
export SFDC_REFRESH_TOKEN="your_refresh_token"
232+
233+
datacustomcode run ./payload/entrypoint.py
234+
```
235+
198236

199237
#### `datacustomcode init`
200238
Initialize a new development environment with a code package template.
@@ -312,26 +350,25 @@ You can read more about Jupyter Notebooks here: https://jupyter.org/
312350

313351
1. Log in to Salesforce as an admin. In the top right corner, click on the gear icon and go to `Setup`
314352
2. On the left sidebar, expand `Apps`, expand `External Client Apps`, click `Settings`
315-
3. Toggle on `Allow access to External Client App consumer secrets via REST API`
316-
4. Expand `Apps`, expand `External Client Apps`, click `External Client App Manager`
317-
5. Click `New External Client App` button
318-
6. Fill in the required fields within the `Basic Information` section
319-
7. Under the `API (Enable OAuth Settings)` section:
353+
3. Expand `Apps`, expand `External Client Apps`, click `External Client App Manager`
354+
4. Click `New External Client App` button
355+
5. Fill in the required fields within the `Basic Information` section
356+
6. Under the `API (Enable OAuth Settings)` section:
320357
1. Click on the checkbox to Enable OAuth Settings
321358
2. Provide a callback URL like `http://localhost:5555/callback`
322-
3. In the Selected OAuth Scopes, make sure that `refresh_token`, `api`, `cdp_query_api`, `cdp_profile_api` is selected
359+
3. In the Selected OAuth Scopes, make sure that `refresh_token`, `api`, `cdp_query_api`, `cdp_profile_api` are selected
323360
4. Check the following:
324361
- Enable Authorization Code and Credentials Flow
325362
- Require user credentials in the POST body for Authorization Code and Credentials Flow
326363
5. Uncheck `Require Proof Key for Code Exchange (PKCE) extension for Supported Authorization Flows`
327364
6. Click on `Create` button
328-
8. On your newly created External Client App page, on the `Policies` tab:
365+
7. On your newly created External Client App page, on the `Policies` tab:
329366
1. In the `App Authorization` section, choose an appropriate Refresh Token Policy as per your expected usage and preference.
330367
2. Under `App Authorization`, set IP Relaxation to `Relax IP restrictions` unless otherwise needed
331-
9. Click `Save`
332-
10. Go to the `Settings` tab, under `OAuth Settings`. There, you can use the `Consumer Key and Secret` button to obtain the `client_id` and `client_secret` used during configuring credentials using this SDK
333-
11. Logout
334-
12. Use the URL of the login page as the `login_url` value when setting up the SDK
368+
8. Click `Save`
369+
9. Go to the `Settings` tab, under `OAuth Settings`. There, you can click on the `Consumer Key and Secret` button which will open a new tab. There you can copy the `client_id` and `client_secret` values which are to be used during configuring credentials using this SDK.
370+
10. Logout
371+
11. Use the URL of the login page as the `login_url` value when setting up the SDK
335372

336373
You now have all fields necessary for the `datacustomcode configure` command.
337374

src/datacustomcode/cli.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,34 +106,18 @@ def _configure_oauth_tokens(
106106
@click.option(
107107
"--auth-type",
108108
type=click.Choice(["oauth_tokens", "username_password"]),
109-
default=None,
109+
default="oauth_tokens",
110110
help="""Authentication method to use.
111111
112112
\b
113-
oauth_tokens - OAuth tokens (refresh_token/core_token) authentication
113+
oauth_tokens - OAuth tokens (refresh_token/core_token) authentication [DEFAULT]
114114
username_password - Traditional username/password OAuth flow
115115
""",
116116
)
117117
def configure(profile: str, auth_type: str) -> None:
118118
"""Configure credentials for connecting to Data Cloud."""
119119
from datacustomcode.credentials import AuthType
120120

121-
# If auth_type not specified, prompt for it
122-
if auth_type is None:
123-
click.echo("\nSelect authentication method:")
124-
click.echo(" 1. OAuth Tokens [default]")
125-
click.echo(" 2. Username/Password")
126-
choice = click.prompt(
127-
"Enter choice",
128-
type=click.Choice(["1", "2"]),
129-
default="1",
130-
)
131-
auth_type_map = {
132-
"1": "oauth_tokens",
133-
"2": "username_password",
134-
}
135-
auth_type = auth_type_map[choice]
136-
137121
# Common fields for all auth types
138122
click.echo(f"\nConfiguring {auth_type} authentication for profile '{profile}':\n")
139123
login_url = click.prompt("Login URL")

0 commit comments

Comments
 (0)