5

I'm developing a new managed package that will include a connected app. I created a connected app in a scratch org and committed it to version control. Then, when pushing the source to a new scratch org, I encountered the following error:

The consumer key is already taken.

I assume that this is because every time a connected app's source file is pushed to a new org, a new connected app is created and they obviously cannot share a consumer key.

My question is; in which org should I create the connected app if it needs to be used in all the scratch orgs that are used for development? Do I need to create an unmanaged package in a traditional development org and install it in each new scratch org after pushing the rest of the project's source?

I could create a new connected app in each scratch org but this wouldn't be viable for testing because the web server calling out to Salesforce would need to know the app credentials beforehand-- it couldn't reference multiple new credentials for each new connected app.

2

Connected apps can't be created as unnmanaged package.

Technically you need connected app only in your Dev hub and all other orgs where you at deploying metadata except scratch orgs .

In scratch orgs you do not need connected apps .Scartch orgs can be authenticated from same machine or command line that created them ,so no need .

I would recommend creating managed packages for connected app as it eases deployment .

You will also need to assign the connected app to the profile that's used in deployment for rest of the orgs.

  • Is it correct that any org can authenticate with a connected app's credentials, regardless of whether the app has been installed in that org? – salesforce-hacker Nov 6 '17 at 20:11
  • Only Scartch org if created via the CLI .Others app need connected apps – Mohith Shrivastava Nov 7 '17 at 1:38
  • Do you have an idea in the case of Canvas App in Managed Package? – Prasanna Jan 25 '18 at 7:24
  • 4
    i disagree somewhat - connected apps in scratch orgs are a valid use case since it's good practice to have dev mimic prod as close as possible. additionally there are some workarounds that require connected apps such as using github.com/financialforcedev/apex-mdapi with automated users/limited profile users (see gscloudsolutions.com/blogpost/…). it would be useful to be able to define these in code and have the key autogenerated when pushed to scratch orgs. – hackerhasid Apr 9 '18 at 19:35
1

I found the following in the Special Behavior in Metadata API Deployments:

Connected App

  • You cannot set the consumerKey in Metadata API. It is included in a retrieve operation for informational purposes. If you try to move the connected app to another org, you must remove the consumerKey from the .zip file before the deployment to an org. A new key will be generated in the destination org.

This makes sense. While you can retrieve the consumerKey if you need it via the Metadata API, you shouldn't be deploying it to each org. This includes scratch orgs.

So, you can have the connectedApp included in the scratch org metadata. Just make sure you exclude the oauthConfig.consumerKey.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.