OauthCustomScope defines a custom OAuth permission describing the protected data a connected app can access in an external system when Salesforce acts as the OAuth authorization provider. The scope in Salesforce corresponds to a scope defined in the external system and assigned to its protected resource, such as an API.
Creating the scope and assigning it to a connected app does not, by itself, grant access to that resource. The external system validates the app's access token and scope before allowing access. The scope's discovery visibility and package protection settings control separate concerns; neither replaces that validation.
Key Elements
| Element | What the Element Controls |
|---|---|
assignedTo |
Repeatable assignment entries that associate the scope with connected apps. Each entry contains a nested connectedApp element. |
connectedApp |
The connected app's name within an assignedTo entry. For a packaged app, use <namespace_prefix>__<connected_app>, with two underscores between the namespace and app name. |
description |
Required. Describes the permission provided by the scope. The documented constraints require a unique value containing only alphanumeric characters, with a maximum length of 60 characters. It can reference a custom label instead of containing literal text; the same formatting requirements apply. |
developerName |
Required. The name used to refer to the scope programmatically. It is separate from the primary label. |
masterLabel |
Required. The scope's primary label. It must be unique, begin with a letter, and contain only alphanumeric characters and underscores. Spaces are not allowed. |
isProtected |
Required boolean: true or false. When true, components created in the installing org cannot link to or reference this protected component. |
isPublic |
Boolean: true or false. Determines whether the scope appears in the connected app's OpenID Connect discovery endpoint. Defaults to false. |
Behavior and Constraints
You need the Manage Connected Apps permission to access this metadata.
The Salesforce scope must correspond to the scope defined in the external system and assigned to the resource. Assigning that scope to the requesting connected app establishes the Salesforce-side association. The external system still decides whether the app's token and scope permit access.
isPublic controls discovery, not public access. OpenID Connect discovery provides an endpoint through which clients obtain information about an authorization provider. Setting isPublic to true includes the scope in the connected app's discovery endpoint; it does not make protected data anonymously accessible.
isProtected controls references to a package component. Its restriction applies to components created in the installing org, not to the external system's token or scope checks. It is not an alternative to resource authorization.
A custom label in description provides centrally maintained, reusable text that can be translated into multiple languages. This creates a dependency on that label and does not remove the description formatting constraints.
Deployment and Retrieval
OauthCustomScope components use the .oauthcustomscope suffix and reside in the oauthcustomscopes directory. The type extends Metadata and inherits its fullName field.
In package.xml, use OauthCustomScope as the type name and the component name as the member. For example, a scope component named basicScope uses basicScope as its manifest member. The type also supports the wildcard member *.
Represent assignments as nested entries, not as plain strings. For example, an assignedTo entry can contain <connectedApp>MyOrgNamespace__TestApp</connectedApp>. Repeat assignedTo for additional assignments. The app value identifies the connected app by name, not by record ID.
Assignments identify connected apps that the scope uses, and a custom label referenced by description creates a label dependency. For packaged connected apps, preserve the namespace prefix and the two underscores separating it from the app name.
Relationships
The scope has a name-based association with ConnectedApp through the nested connectedApp value in each assignedTo entry. The corresponding external scope and resource are configured in the external system; this metadata component does not create them.
References
-
CustomLabel:descriptioncan reference a label instead of containing literal descriptive text.
Documentation Inconsistencies
The field table describes assignedTo as an enumeration of type string, but Salesforce's metadata example uses a structured assignedTo entry containing connectedApp. Use the nested representation for assignments.
The documented description rule allows only alphanumeric characters, but Salesforce's sample description contains spaces. The sample does not establish that spaces satisfy the documented constraint. The stated uniqueness, alphanumeric-only, and 60-character requirements also apply when a custom label supplies the description.
Common Questions
How do I retrieve all OAuth custom scopes?
Use OauthCustomScope as the type name in package.xml and * as the member. Retrieved components use the .oauthcustomscope suffix in the oauthcustomscopes directory.
How do I assign a custom scope to a packaged connected app?
Add an assignedTo entry with a nested connectedApp value in the form <namespace_prefix>__<connected_app>. Use two underscores between the package namespace and app name.
Does isPublic make the protected API publicly accessible?
No. isPublic only controls whether the scope appears in the connected app's OpenID Connect discovery endpoint. The external system still validates the access token and scope.
Can an OAuth custom scope description use a custom label?
Yes. description can reference a custom label for reusable, translatable wording. The label becomes a dependency, and the documented description formatting requirements still apply.
What permission is required to access OauthCustomScope metadata?
The required permission is Manage Connected Apps.