Přeskočit na obsah

The Golden Pass, by Hand

Tento obsah zatím není dostupný ve vašem jazyce.

Lab for chapter 11, The Burger House: Flows Without a Person, in Securing Salesforce: Identity and Access. The practice asks why each of these steps matters; this page is how to do them.

You’ll buildA key pair, the Burger House’s external client app with the JWT bearer flow and one pre-authorized permission set, and a JWT you sign yourself that gets a token for Priya while she’s not there
TimeAbout 40 minutes (measured in the lab test, November 2026)
OrgThe service provider org from chapters 4 to 9
Start fromPriya, a Standard User who can edit Accounts she owns
FilesNone to download. You make the key pair yourself
You needmacOS or Linux, or Windows with Git Bash: bash or zsh, openssl and curl
TestedWinter ‘27 (API 68.0), November 2026
  • Log in to the service provider org as the admin.

  • Make a folder of your own for this lab, such as ~/burger-house-lab, not a temporary folder: the computer may empty those overnight, and your key with them. Open a terminal in it.

  • Set the org’s address, with your own My Domain:

    Terminal window
    B=https://bluefin-lab-sp-dev-ed.develop.my.salesforce.com

In the lab test, Priya owned no Account. As the admin, open the Accounts tab, select New, enter Account Name Burger House Friday Orders (lab), and Save. Then change its Account Owner to Priya Sharma. Copy the Account’s ID from the address bar: it starts with 001.

Terminal window
ACCOUNT_ID=paste-the-001-id-here

Step 2: Make the Burger House’s key and certificate

Section titled “Step 2: Make the Burger House’s key and certificate”

In your folder:

Terminal window
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt -subj "/CN=Burger House lab"

server.key is the private key, the seal. server.crt is the certificate, what Salesforce checks the seal against: about 1 KB, well under Salesforce’s 4 KB limit. Only the certificate ever leaves your folder.

  1. From Setup, in Quick Find, enter Permission Sets, select Permission Sets, then New.
  2. Label: Burger House: act as. License: —None—. Select Save.
  3. Select Manage Assignments, Add Assignment, tick Priya Sharma only, Next, keep No expiration date, and select Assign.

It carries no permissions. It’s the list of people the Burger House may act as.

  1. From Setup, open External Client App Manager, and select New External Client App.

  2. External Client App Name: Burger House. Check that API Name reads Burger_House. Contact Email: your address. Distribution State: Local.

  3. Open API (Enable OAuth Settings) and tick Enable OAuth.

    • Callback URL: http://localhost:1717/OauthRedirect. This flow never uses it, but the app needs one.
    • OAuth Scopes: move Manage user data via APIs (api) and Perform requests at any time (refresh_token, offline_access) to Selected OAuth Scopes.
    • Under Flow Enablement, tick Enable JWT Bearer Flow. Under Certificate Upload, select Upload Files and choose server.crt.
  4. Select Create.

    Flow Enablement with Enable JWT Bearer Flow ticked, and under Certificate Upload, the file burger-house-lab.crt.

    The certificate Salesforce checks the seal against (Salesforce, Setup in a Developer Edition org, screenshot, November 2026). Full size

Watch out. The JWT bearer flow never gives back a refresh token, but the app still needs the refresh_token scope. In the lab test, with only api, every pass was refused: “refresh_token scope is required and the connected app should be installed and preauthorized.”

  1. On the Policies tab, select Edit, open OAuth Policies, and set Permitted Users to Admin approved users are pre-authorized. Salesforce asks you to confirm: “Enabling this option will result in all users currently using this app being denied access.” Select OK.

  2. Under App Policies, which now shows Select Profiles and Select Permission Sets, move Burger House: act as to Selected Permission Sets, and select Save.

    The app's App Policies in edit: Select Profiles empty, and Burger House: act as under Selected Permission Sets.

    The short list of who the app may act as (Salesforce, Setup in a Developer Edition org, screenshot, November 2026). Full size

  3. On the Settings tab, open OAuth Settings, select Consumer Key and Secret, and copy the key. You won’t need the secret. In your terminal (zsh; in bash: read -rsp "Consumer key: " CLIENT_ID):

    Terminal window
    read -rs "CLIENT_ID?Consumer key: "; echo

Put in Priya’s username, then run the rest as it is:

Terminal window
USERNAME="priya.sharma@bluefin-lab-sp.example.com"
b64url() { openssl base64 -A | tr '+/' '-_' | tr -d '='; }
HEADER=$(printf '{"alg":"RS256"}' | b64url)
EXP=$(( $(date +%s) + 180 ))
CLAIMS=$(printf '{"iss":"%s","sub":"%s","aud":"https://login.salesforce.com","exp":%s}' "$CLIENT_ID" "$USERNAME" "$EXP" | b64url)
SIG=$(printf '%s.%s' "$HEADER" "$CLAIMS" | openssl dgst -sha256 -sign server.key | b64url)
JWT="$HEADER.$CLAIMS.$SIG"
echo "$HEADER"

You should see eyJhbGciOiJSUzI1NiJ9, exactly as in Salesforce’s example. That’s the header. The claims say who it’s from (iss, your key), who it’s for (sub, Priya), where it’s going (aud) and when it expires (exp, three minutes from now). The signature is the first two, sealed with server.key.

Within three minutes:

Terminal window
curl -s -X POST "$B/services/oauth2/token" --data-urlencode grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer --data-urlencode "assertion=$JWT"

You should see an access_token, "scope":"api", your instance_url, and an id that ends in Priya’s user ID. Look for a refresh token: there isn’t one.

Terminal window
AT=paste-the-access_token-here

Tip. In the lab test, a Developer Edition accepted aud as https://login.salesforce.com, as the org’s own My Domain address, and as https://test.salesforce.com. https://example.com was refused: “audience is invalid”. Use https://login.salesforce.com for a production or Developer Edition org, as Salesforce’s page for this flow says.

Terminal window
curl -s -o /dev/null -w "%{http_code}\n" -X PATCH "$B/services/data/v68.0/sobjects/Account/$ACCOUNT_ID" -H "Authorization: Bearer $AT" -H "Content-Type: application/json" -d '{"Description":"Friday delivery done"}'

You should see 204: done, nothing to say. Open the Account in Salesforce. Description: “Friday delivery done”. Last Modified By: Priya Sharma. Not an integration user, and not you. And Priya never signed in.

Each break below builds a new pass, so run step 5’s lines again with the change, then step 6.

  1. Someone not on the list. Set USERNAME to your admin’s username.

    You should see "error":"invalid_app_access", “user is not admin approved to access this app”.

  2. A tampered pass. Build a good pass for Priya (step 5), then swap in claims for someone else and keep Priya’s signature:

    Terminal window
    CLAIMS2=$(printf '{"iss":"%s","sub":"%s","aud":"https://login.salesforce.com","exp":%s}' "$CLIENT_ID" "your-admin-username" "$EXP" | b64url)
    JWT="$HEADER.$CLAIMS2.$SIG"

    You should see "error":"invalid_client", “invalid client credentials”.

Watch out. A pass whose seal doesn’t match its claims doesn’t get a “bad signature” answer: Salesforce says “invalid client credentials”. If you see that with a key you know is right, check that the pass wasn’t changed after it was signed, and that the app has the certificate that matches your server.key.

  1. An old pass. Set EXP=$(( $(date +%s) - 600 )), ten minutes ago, and build and present it.

    You should see "error":"invalid_grant", “expired authorization code”.

Tip. In the lab test, a pass that had expired 60 seconds before was still accepted; four minutes was refused. Salesforce allows a little difference between clocks. Don’t rely on it: give each pass three minutes and use it at once.

Tip. Login History shows every try: in the lab test, Success, Failed: Audience Invalid, Failed: Not approved for access and, for the tampered pass, Failed: Missing Consumer Key Parameter, each with the application Burger House. That’s where an admin looks when a nightly job stops working.

  1. Revoke the token:

    Terminal window
    curl -s -o /dev/null -w "%{http_code}\n" -X POST "$B/services/oauth2/revoke" --data-urlencode "token=$AT"
  2. Clear the variables: unset CLIENT_ID USERNAME JWT AT SIG CLAIMS CLAIMS2.

  3. Keep the app and the permission set for now: later chapters may use them. When you’re finished with the course, remove Priya from Burger House: act as, turn off the JWT bearer flow, and delete server.key.

Watch out. Whoever has server.key and the consumer key can get a token as anyone in Burger House: act as, with no password and no MFA. Keep the key in your own folder, never in a repository, an email or a chat. And keep the permission set short.

  • Burger House has the JWT bearer flow, your certificate, the scopes api and refresh_token, and Admin approved users are pre-authorized with Burger House: act as.
  • Priya is the only one in Burger House: act as.
  • Your pass got a token whose id ends in Priya’s user ID, and no refresh token.
  • Her Account says “Friday delivery done”, last modified by Priya.
  • The admin’s pass, the tampered pass and the old pass were all refused.
  • server.key is only in your own folder.

From the lab test, November 2026:

  • “refresh_token scope is required…”. Add Perform requests at any time (refresh_token, offline_access) to the app (step 4).
  • invalid_app_access. The user isn’t in Burger House: act as, or the permission set isn’t on the app’s policies (steps 3 and 4).
  • “invalid client credentials”. The pass was changed after signing, the consumer key is wrong, or the app has a different certificate (step 8).
  • “audience is invalid”. Check aud (step 6).
  • “expired authorization code”. More than three minutes passed: build a new pass (step 5).
  • “user hasn’t approved this consumer”. The username in sub doesn’t exist in this org; check the spelling.

Module 3 sets the SAML bearer assertion flow beside this one: the same idea, with a signed SAML assertion instead of a JWT. This lab doesn’t build it. Signing a SAML assertion needs an XML signing tool on your computer, and the lab test didn’t try it with an external client app: check Salesforce’s current page for the flow before you build one.

A system with nothing but a private key got a token for a named person who wasn’t there, and changed her record as her. Salesforce checked four things before saying yes: that the pass was sealed by the key whose certificate it holds, that it was for this org, that it hadn’t expired, and that the person was on the app’s short list. Change any one, and it said no.

Next lab: more labs come in a later release, starting with chapter 10, From One Org to the Other, and chapter 12, Getting Users In and Out. Keep both orgs, your apps and Priya’s permission set until then.