Promote an OAuth custom connector without losing its client secret
December 01, 2026
A customer built an OAuth custom connector in development and needed it in UAT. They exported the solution and imported it. The connector arrived, but nobody could sign in, because the OAuth client secret wasn’t in the package.
The fix is solution environment variables, and Microsoft Learn documents the core of it. This post covers that documentation, then adds the parts that cost the customer time: the import settings file, the redirect URL, connections, and a few checks that behave differently than you’d expect.
The problem
When you export a solution that contains a custom connector, the client ID, scopes, and URLs travel with it. The client secret doesn’t. After import, the connector in the target environment has no secret, so sign-in fails until someone types it back in.
Moving the connector this way also carries development values into the target environment, such as the client ID and tenant URLs. Those usually differ per environment.
This applies to any OAuth connector, including the oauth2pkce identity provider that many MCP servers use. Microsoft Learn doesn’t state outright that the secret is left out of the export. That’s what the customer saw, and it’s the reason the Learn guidance matters.
What Microsoft Learn covers
Two Learn articles describe the solution:
- Use environment variables in solution custom connectors
- Use environment variables for Azure Key Vault secrets
Between them, Learn tells you that:
- Custom connector properties
Host,Base URL,Client ID,Client Secret,Login Url, andRefresh Urlcan reference environment variables. - The syntax is
@environmentVariables("environmentVariableName"), and the name is the schema name with the publisher prefix, not the display name. - Values resolve when the connector is saved, so you save the connector again after changing a variable.
- Environment variables aren’t supported in actions, triggers, or policies.
- A Secret variable reads from Azure Key Vault. A Text variable used for a client secret isn’t encrypted.
- To supply new values on import, remove the value from the variable before you export. Import won’t prompt for a variable that already has a current or default value.
- OAuth credentials expire, so renew them before they do. For certified connectors, Learn says to submit the connector update one month before the expiration date.
Learn doesn’t walk through an end-to-end promotion. It leaves out the automated import, the redirect URL, and connections. Those are the next sections.
Which fields to parameterize
Anything that differs per environment is a candidate:
| Field | Where it lives |
|---|---|
| Client ID | Security tab, oAuthSettings.clientId |
| Client secret | Security tab, oAuthSettings.clientSecret |
| Authorization URL or login URL | Security tab |
| Token URL | Security tab, customParameters.tokenUrl |
| Refresh URL | Security tab, customParameters.refreshUrl |
| Host and Base URL | General tab |
The client secret is the one that has no other way to move. The rest save you from editing the connector after every import.
Reference the variables in the connector
In apiProperties.json, the OAuth settings look like this:
"oAuthSettings": {
"identityProvider": "oauth2pkce",
"clientId": "@environmentVariables(\"contoso_ClientId\")",
"clientSecret": "@environmentVariables(\"contoso_ClientSecret\")",
"scopes": ["<your scopes>"],
"customParameters": {
"authorizationUrl": { "value": "<authorization URL>" },
"tokenUrl": { "value": "@environmentVariables(\"contoso_TokenUrl\")" },
"refreshUrl": { "value": "@environmentVariables(\"contoso_TokenUrl\")" }
}
}
In the connector designer, type the same expression into the field on the Security or General tab. The secret field shows masked text, but you still enter the expression.
Set up the source environment
- Put the connector in a solution. If you created it outside one, open the solution and select Add existing > Automation > Custom connector.
- Select New > More > Environment variable and create one variable for each value that differs per environment.
- Set the client secret variable to the Secret data type and store the value in Azure Key Vault.
- Edit the connector and replace each value with its
@environmentVariables("<schema name>")expression. - Save the connector.
Configure Key Vault once
The Key Vault setup is where most of the time goes. The Learn checklist boils down to:
- Register the
Microsoft.PowerPlatformresource provider in the subscription that holds the vault. - Grant the Key Vault Secrets User role to the people who create the variable and to the Dataverse service principal (application ID
00000007-0000-0000-c000-000000000000). - Keep the vault in the same tenant as your Power Platform environment.
- If the vault firewall is on, allow the Power Platform IP ranges. The “Trusted Services Only” option doesn’t include Power Platform.
- Use a separate vault for each Power Platform environment, which Learn recommends to limit the damage from a breach.
The AllowedBots and AllowedEnvironments tags in the Learn article apply when a Copilot Studio agent reads the secret directly. The connector scenario doesn’t use them.
Export without the development values
Learn’s rule is that a variable with a value in the solution doesn’t prompt on import. If a variable still holds a value you don’t want to ship, remove that value from the variable, then export. The value stays in the development environment, and the target environment supplies its own.
Also check what you’re committing. Variable values export in separate JSON files inside the solution zip, so a Text variable holding a secret ends up in source control. Another reason to use Key Vault.
Import with a settings file
Interactive imports prompt for variables that have no value. For automated deployments, generate a settings file from the exported solution:
pac solution create-settings --solution-zip <solution>.zip --settings-file <settings>.json
Fill in the target values:
{
"EnvironmentVariables": [
{ "SchemaName": "contoso_ClientId", "Value": "<UAT client ID>" },
{ "SchemaName": "contoso_ClientSecret", "Value": "<UAT Key Vault secret reference>" },
{ "SchemaName": "contoso_TokenUrl", "Value": "<UAT token URL>" }
],
"ConnectionReferences": []
}
Then import:
pac solution import --path <solution>.zip --environment <target URL or ID> --settings-file <settings>.json --publish-changes
For a Secret variable, the value you pass is the reference to the secret in the target environment’s vault, not the secret itself. Confirm the exact format against a variable you’ve already created in the target environment before you automate it. The pac reference describes the settings file as “deployment settings for connection references and environment variables” and doesn’t show a Key Vault example.
After import
Three things still need attention, and none of them are in the connector article.
- Save the connector once in the target environment. Values resolve at save time, so the connector isn’t using the target values until you do.
- Register the new redirect URL. The platform generates a per-connector redirect URL that includes the environment ID, so the target environment gets a different URL than the source. Copy it from the connector’s Security tab and add it to the allowed redirect URLs on the OAuth app you registered with the service provider. Sign-in fails until you do, with or without environment variables.
- Re-create the connections. Connections don’t move with a solution. Map or create a connection reference for each app, flow, or agent that uses the connector, then have users sign in again.
What changes with environment variables
| Item | Without environment variables | With environment variables |
|---|---|---|
| Client secret | Not in the package. Re-enter by hand. | The reference travels. You supply the value at import. |
| Client ID | Development value carries over. | The reference travels. You supply the value at import. |
| Redirect URL | Regenerated for the target environment. | Regenerated for the target environment. Register it either way. |
| Connections | Not promoted. | Not promoted. |
Troubleshooting
| Symptom | Likely cause and fix |
|---|---|
| Sign-in fails right after import | The target environment’s redirect URL isn’t registered on the OAuth app. Add it. |
| Invalid client or unauthorized error | The client ID or secret variable has the wrong value for this environment, or you haven’t saved the connector since the value changed. Correct the value and save. |
| The expression shows up as literal text in a request or URL | The expression is in an action or policy, which don’t support environment variables, or the schema name is wrong. Use the schema name with the publisher prefix. |
| Import doesn’t prompt for values | The variable already has a default or current value in the solution or target. Remove the value before exporting, or supply a settings file. |
| Users are asked to connect again | Expected. Connections are per environment. |
Verify by signing in
Downloaded connector definitions, whether from pac connector download or the portal, always show the @environmentVariables(...) text and never the resolved value. They also never return a client secret, so you can’t confirm the secret by reading the connector back.
The reliable check is to sign in through the connector in the target environment. If it fails, confirm that the OAuth app allows the target redirect URL and that the credentials were issued for that environment’s tenant.