JIT Sandbox Authentication

This feature requires sfp-pro with sfp-server

JIT (Just-In-Time) sandbox authentication generates sandbox credentials on-demand via the parent production org, eliminating the need to store and manage individual sandbox credentials. This feature only works provided the sandbox is refreshed /created using the same user that is registered as production org in the sfp server

How JIT Authentication Works

Instead of storing credentials for each sandbox, sfp-server:

  1. Stores the parent production org's credentials

  2. Uses Salesforce's sandbox auth API to generate credentials when needed

  3. Returns short-lived credentials for the requested sandbox

┌─────────────────────────────────────────────────────────────────┐
│                    JIT Authentication Flow                      │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Request sandbox access                                        │
│          │                                                      │
│          ▼                                                      │
│   sfp-server checks: Is this a JIT sandbox?                     │
│          │                                                      │
│          │ Yes                                                  │
│          ▼                                                      │
│   Retrieve parent production credentials                        │
│          │                                                      │
│          ▼                                                      │
│   Connect to production org                                     │
│          │                                                      │
│          ▼                                                      │
│   Call Salesforce Sandbox Auth API                              │
│   POST /services/data/vXX.0/tooling/sandboxAuth                 │
│          │                                                      │
│          ▼                                                      │
│   Receive sandbox auth fields                                   │
│          │                                                      │
│          ▼                                                      │
│   Return credentials to user                                    │
│   (accessToken + instanceUrl OR sfdxAuthUrl)                    │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Benefits of JIT Authentication

Traditional Approach
JIT Approach

Store credentials for each sandbox

Only store production credentials

Re-authenticate after sandbox refresh

Automatic - uses production auth

Manage N sandbox credentials

Manage 1 production credential

Risk of stale credentials

Always fresh credentials

Setting Up JIT Sandboxes

Step 1: Register the Production Org

Step 2: Register Sandbox with Parent

This creates a "JIT registration" - the sandbox is registered but no credentials are stored:

Step 3: Create Environment (Optional)

Link the JIT sandbox to an environment:

Using JIT Sandboxes

Direct Sandbox Access

Behind the scenes:

  1. Server sees this is a JIT sandbox

  2. Retrieves production credentials

  3. Calls sandbox auth API

  4. Returns fresh sandbox credentials

Via Environment

Sandbox Refresh Handling

JIT authentication automatically handles sandbox refreshes:

No manual credential update needed!

When JIT Auth is Used

sfp-server automatically uses JIT authentication when:

  1. The org is registered with is_jit_registration = true

  2. No stored credentials exist (sfdx_auth_url_encrypted = NULL)

  3. A parent_production_username is set

CI/CD Integration

Standard Usage

Multi-Sandbox Pipeline

Mixing JIT and Traditional Auth

You can have both JIT and traditionally-registered sandboxes:

Troubleshooting

"Parent production org not found"

The parent org isn't registered:

"Unable to generate JIT auth"

  • Verify the production org credentials are valid

  • Check that the sandbox exists and is active

  • Ensure the user has access to the sandbox

"Sandbox not found"

The sandbox may have been refreshed with a different name:

JIT Auth Slow

JIT authentication involves an API call to production. If consistently slow:

  • Check production org API limits

  • Consider using traditional auth for high-frequency sandboxes

Limitations

  • Requires Production Access: User must have access to the parent production org

  • API Call Required: Each JIT auth makes an API call to production

  • Sandbox Must Exist: JIT can't authenticate to non-existent sandboxes

  • Full Sandboxes Only: JIT works with sandboxes, not scratch orgs

Last updated