fix(auth): let non-admins authenticate to the Tooling API - #21
Open
RubenHalman wants to merge 1 commit into
Open
fix(auth): let non-admins authenticate to the Tooling API#21RubenHalman wants to merge 1 commit into
RubenHalman wants to merge 1 commit into
Conversation
Reading the Consumer Key from Flow_Scanner_OAuth_Config_Protected__mdt was gated on Consumer_Key__c.isAccessible(). That check returns false for every non-admin subscriber user, so ToolingAPI threw 'Insufficient permissions to access OAuth configuration' and the app fell back to its setup wizard for anyone without Customize Application. The gate bought no security: the custom metadata type is *protected*, so its records are only readable by Apex inside this package's namespace regardless of the running user's field permissions. Setup actions that write the config remain admin-gated via LFSSetupController.requireAdmin(). No unit test accompanies this: the behaviour only reproduces with the managed package installed in a subscriber org. In an unmanaged scratch org the type is not protected, so isAccessible() returns true for a standard user and a test passes with or without the guard. Verified manually instead — see PR body. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A non-admin user with the Flow Scanner permission set can't use the app at all. The Scan Flows tab falls back to the setup wizard with:
The underlying error, pulled off the wire in a subscriber org, is:
Cause
One guard, in two places —
ToolingAPI.getProductionAccessToken()andLFSSetupController.getConfig():isAccessible()on that field returnsfalsefor every non-admin subscriber user, so the Consumer Key can never be read and the JWT is never minted. InLFSSetupControllerthe same guard returnsnull, sogetSetupStatus()also reports "Consumer Key not configured" to non-admins even when it is configured.The guard buys no security.
Flow_Scanner_OAuth_Config_Protected__mdtis a protected custom metadata type, so its records are only readable by Apex inside this package's namespace no matter what the running user's field permissions say. The namespace boundary is the control; the FLS check just excludes non-admins.Writes are unaffected —
saveConsumerKey()andtestConnection()still go throughrequireAdmin().Reproduction
In a subscriber org with the managed package installed (
flow-scanner3.4.0.1):Read Onlyprofile and assign theFlow Scannerpermission set.ApiEnabled,ViewSetup,ViewRoles,ViewAllCustomSettings.Insufficient permissions to access OAuth configurationin the Aura response.Reverting the same user to System Administrator makes it work immediately.
Why there's no unit test
This only reproduces with the managed package in a subscriber org. In an unmanaged scratch org the type isn't protected, so
isAccessible()returnstruefor a standard user and any such test passes with or without the guard — I wrote one, confirmed it passed with the bug deliberately reintroduced, and removed it rather than ship false comfort.Validated instead by deploying this branch to a fresh scratch org: 39/39 local tests pass, 85% coverage.
Two related things worth a separate look
lfscanner__Flow_Scannerto the External Client App's OAuth policies fails withCannot modify managed object: entity=SetupEntityAccess. Admins have to create a throwaway unmanaged permission set purely to authorize the app. That isn't indocs/installation.md.docs/installation.mdsteps 3–4 can't be followed in some orgs.ExternalClientAppManager/home,ExternalClientApps/homeandExternalClientAppSettings/homeall return "Page not found" in a current Developer Edition org. The Metadata API route works (ExternalClientApplication+ExtlClntAppOauthSettings+ExtlClntAppGlobalOauthSettings+ExtlClntAppOauthConfigurablePolicies, deployed together — the OAuth settings and global settings must be in the same deploy).🤖 Generated with Claude Code