See Scopes Work
Bu içerik henüz dilinizde mevcut değil.
Lab for chapter 8, OAuth: The Base Pattern, in Securing Salesforce: Identity and Access. The practice asks why each of these steps matters; this page is how to do them.
| You’ll build | An API-only integration user, a client credentials external client app that runs as it, and a token you watch being refused, widened, checked and revoked |
| Time | About 40 minutes (measured in the lab test, November 2026) |
| Org | The service provider org from chapters 4 to 7 (any Developer Edition works) |
| Start from | An org where you can log in as the admin, with MFA |
| Files | None |
| You need | A terminal with curl (built into macOS, Linux and Windows 10 and later) and python3 to make the answers readable (optional) |
| Tested | Winter ‘27 (API 68.0), November 2026 |
Before you start
Section titled “Before you start”- Log in to the service provider org as the admin, and check the logo.
- Open a terminal. Every call below runs there. Nothing in this lab needs the Salesforce CLI.
Step 1: Make the integration user
Section titled “Step 1: Make the integration user”-
From Setup, in Quick Find, enter
Users, select Users, then New User. -
First Name
Reporting, Last NameIntegration. Email: an address you can read. Username:reporting.integration@bluefin-lab-sp.example.com. It doesn’t have to be a real mailbox, but it must be unique across all of Salesforce. -
User License: Salesforce Integration. Profile: Minimum Access - API Only Integrations.
-
Untick Generate new password and notify user immediately, and select Save.

The integration license and the minimal API-only profile (Salesforce, Setup in a Developer Edition org, screenshot, November 2026). Full size
Watch out. When you choose the Salesforce Integration license, the Profile list offers two profiles, and in the lab test it came up on Salesforce API Only System Integrations. Choose Minimum Access - API Only Integrations: it starts with almost nothing, and you add only what the job needs.
Tip. If you forget to untick the password box, Salesforce emails the user a link to set a password. Ignore it: with an API-only profile, the user can’t log in to Salesforce in a browser anyway.
-
On the saved user, in Permission Set License Assignments, select Edit Assignments, tick Salesforce API Integration, and select Save.
You should see Salesforce API Integration listed, with today’s date.
In the lab test, a new Developer Edition had one Salesforce Integration license and one Salesforce API Integration permission set license, both unused.
Step 2: Let it read Accounts, and nothing else
Section titled “Step 2: Let it read Accounts, and nothing else”-
From Setup, in Quick Find, enter
Permission Sets, select Permission Sets, then New. -
Label:
Reporting tool: read Accounts. License: Salesforce API Integration. Select Save. -
Select Object Settings, Accounts, Edit, tick Read only, and Save.
-
Select Manage Assignments, Add Assignment, tick Reporting Integration, Next, keep No expiration date, and select Assign.
You should see “1 assignments were successful”.
Step 3: Make one Account
Section titled “Step 3: Make one Account”A new Developer Edition has no Accounts, so there would be nothing to read. As the admin, open the Accounts tab (App Launcher, Accounts), select New, enter Account Name Example Account (lab), and Save.
Watch out. In the lab test, a new Developer Edition had no Accounts and no Opportunities. A query that works but finds nothing looks the same as a query that’s allowed to see nothing: make one record first.
Step 4: Make the app
Section titled “Step 4: Make the app”-
From Setup, in Quick Find, enter
External Client App, select External Client App Manager, then New External Client App. -
External Client App Name:
Reporting tool. Contact Email: your address. Distribution State: Local. -
Open API (Enable OAuth Settings) and tick Enable OAuth.
- Callback URL:
https://localhost/callback. This flow doesn’t use it, but the field is required. - OAuth Scopes: move only Access the identity URL service (id, profile, email, address, phone) to Selected OAuth Scopes.
- Under Flow Enablement, tick Enable Client Credentials Flow. Salesforce asks you to confirm: “Anyone with the consumer key and consumer secret can access your org on behalf of the selected user.” Select OK.
- Callback URL:
-
Leave the rest as it is, and select Create.

One narrow scope to start: the identity URL only (Salesforce, Setup in a Developer Edition org, screenshot, November 2026). Full size
Under Security, three boxes come ticked and can’t be changed: Require Proof Key for Code Exchange (PKCE)…, Enable Refresh Token Rotation, and Limit Idle Refresh Token Time-to-Live (TTL) to 30 Days, each with “To change this required setting, contact Support.” They’re for flows with a person; chapter 9 meets them.
Step 5: Choose who it runs as
Section titled “Step 5: Choose who it runs as”-
On the app, select the Policies tab, then Edit, and open OAuth Policies.
-
Under OAuth Flows and External Client App Enhancements, tick Enable Client Credentials Flow, and in Run As (Username), enter the integration user’s username.
-
Leave Permitted Users and IP Relaxation (Enforce IP restrictions) as they are, and select Save.
You should see “Success! The external client app Reporting tool was saved.”
Enforce IP restrictions means the integration user’s own login IP ranges apply to this app’s tokens. Its profile has none in a new org, so your terminal isn’t blocked. In a company, you’d give that profile the reporting tool’s server addresses.
Step 6: Get the key and secret into your terminal
Section titled “Step 6: Get the key and secret into your terminal”-
On the app, select the Settings tab, open OAuth Settings, and select Consumer Key and Secret. Salesforce may email you a code first: that’s the entrance protecting its own keys.
-
In your terminal, put them in two variables without them showing on screen or in your history. On a Mac (zsh):
Terminal window read -rs "KEY?Consumer key: "; echo; read -rs "SECRET?Consumer secret: "; echoIn bash (Linux, Windows’ Git Bash):
read -rsp "Consumer key: " KEY; echo; read -rsp "Consumer secret: " SECRET; echoPaste each one once, then press Return.
-
Set your org’s address, with your own My Domain:
Terminal window B=https://bluefin-lab-sp-dev-ed.develop.my.salesforce.com
Don’t save the key and secret in a file you share, and don’t put them in a screenshot.
Step 7: Get a wristband
Section titled “Step 7: Get a wristband”curl -s -X POST "$B/services/oauth2/token" --data-urlencode grant_type=client_credentials --data-urlencode "client_id=$KEY" --data-urlencode "client_secret=$SECRET"You should see, in the lab test (shortened):
{"access_token":"00D…!AQ…","signature":"…","scope":"id","instance_url":"https://bluefin-lab-sp-dev-ed.develop.my.salesforce.com","id":"https://login.salesforce.com/id/00D…/005…","token_type":"Bearer","issued_at":"…"}Read it field by field, as in module 3. scope is id, and there’s no refresh_token. Copy the token and the id address into two variables:
T=paste-the-access_token-hereID=paste-the-id-address-hereTip. The
idaddress in the answer is on login.salesforce.com, even though you asked your My Domain. It still answers your token: use it as it comes.
Watch out. If the answer is
invalid_client_id, “client identifier invalid”, the key is wrong. In the lab test, it had been pasted twice. Run step 6’sreadagain, and paste once.
Step 8: Show the wristband at two stalls
Section titled “Step 8: Show the wristband at two stalls”-
The identity URL, which
idallows:Terminal window curl -s "$ID" -H "Authorization: Bearer $T"You should see the integration user:
"username":"reporting.integration@…","display_name":"Reporting Integration","asserted_user":true, and a list ofurls. -
A query, which
iddoesn’t allow:Terminal window curl -s "$B/services/data/v68.0/query?q=SELECT+Name+FROM+Account+LIMIT+1" -H "Authorization: Bearer $T"You should see, in the lab test:
[{"message":"This session is not valid for use with the REST API","errorCode":"INVALID_SESSION_ID"}]
v68.0 is Winter ‘27. Your org lists its versions at $B/services/data; the last entry, Latest Release, always points to the newest.
Watch out. A call outside the token’s scope says “This session is not valid for use with the REST API”,
INVALID_SESSION_ID. It sounds like a broken login. It isn’t: the token is good, but its scope doesn’t cover this stall.
Step 9: Widen the scope
Section titled “Step 9: Widen the scope”-
On the app’s Settings tab, Edit, add Manage user data via APIs (api) beside the identity scope, and Save.
-
Get a new wristband (step 7), copy the new token into
T, and run the query again (step 8, 2).You should see
"scope":"api id"in the new answer, and the query returnsExample Account (lab).
In the lab test, a token asked for about 15 seconds after saving already had the new scope.
Step 10: Find the second check
Section titled “Step 10: Find the second check”Query an object the permission set doesn’t give the user:
curl -s "$B/services/data/v68.0/query?q=SELECT+Name+FROM+Opportunity+LIMIT+1" -H "Authorization: Bearer $T"You should see, in the lab test:
[{"message":"\nSELECT Name FROM Opportunity LIMIT 1\n ^\nERROR at Row:1:Column:18\nsObject type 'Opportunity' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. …","errorCode":"INVALID_TYPE"}]The scope says “APIs”. The user says which data. To this user, an object it can’t read doesn’t exist.
Watch out. When an integration user can’t read an object, the query doesn’t say “no permission”: it says the object “is not supported”,
INVALID_TYPE, as if you’d made a typo. Check the user’s permissions before you check your spelling.
Step 11: Take it back
Section titled “Step 11: Take it back”-
Ask the entrance about the token first, so you have something to compare:
Terminal window curl -s -X POST "$B/services/oauth2/introspect" --data-urlencode "token=$T" --data-urlencode "client_id=$KEY" --data-urlencode "client_secret=$SECRET" --data-urlencode token_type_hint=access_tokenYou should see
"active":true,"scope":"id api", the username, andexpandiat: in the lab test, two hours apart. -
Revoke it:
Terminal window curl -s -o /dev/null -w "%{http_code}\n" -X POST "$B/services/oauth2/revoke" --data-urlencode "token=$T"You should see
200. -
Run the Account query again (step 8, 2).
You should see
"Session expired or invalid",INVALID_SESSION_ID: a different message from step 8’s. -
Ask the entrance again (1).
You should see
{"active":false}, and nothing more.
Step 12: Look for what’s missing
Section titled “Step 12: Look for what’s missing”Look back at step 7’s answer: no refresh_token. And in the app’s scope list, nothing would add one to this flow: Salesforce filters full, web and refresh_token out of client credentials.
Clear the variables when you’re done:
unset KEY SECRET T IDCheck your lab
Section titled “Check your lab”- Reporting Integration has the Salesforce Integration license, Minimum Access - API Only Integrations, the Salesforce API Integration permission set license and the permission set.
- Reporting tool runs client credentials as that user.
- The first token had
scopeid: the identity URL answered, the query didn’t. - The second had
api id: Accounts answered, Opportunities didn’t. - After the revoke, the query was refused and introspection said
{"active":false}. - The key and secret aren’t in any file or screenshot you’d share.
If something went wrong
Section titled “If something went wrong”From the lab test, November 2026:
invalid_client_id. The key is wrong or pasted twice (step 7).- The query works but returns
"totalSize":0. There’s no Account yet (step 3), or the permission set isn’t assigned (step 2). - “This session is not valid for use with the REST API”. The token has no
apiscope (step 8), or you’re still using the old token after step 9. - “sObject type … is not supported”. The user can’t read that object (step 10).
- The new token still shows only
id. In the lab test it changed at once; if not, wait a few minutes and ask again.
Keep or clean up
Section titled “Keep or clean up”Keep the user and the app. Later chapters use the service provider org again. The token is already revoked.
What you just proved
Section titled “What you just proved”The app decided what the wristband allowed, not the request: you never asked for a scope, and the answer told you which one you got. The first stall checked the scope and turned the token away; the second check, the user’s own permissions, turned away the Opportunities even with api on the token. And when you took the token back, the entrance said exactly that, and nothing more.
Next lab: chapter 9, The Device Flow, Hands-On.
