Make site dynamic to support SFDX scratch orgs
topherlandry opened this issue · 6 comments
I'm not sure what the best way to accomplish this is, but with SFDX scratch orgs the site needed for OAuth is not login.salesforce.com
but whatever the instance URL of the scratch org is. This is causing problems for me with doing development with SFDX.
One way I could solve this is by loading client_options.site
from an environment variable if it exists and using login.salesforce.com
otherwise.
I'm happy to do the work needed for a PR on this one, but I'm looking for a little bit of a suggestion just to make sure it fits with the project and isn't rejected when submitted.
Hm, good question. I think that's something that we need to know from omniauth itself. Can you pass it a dynamic value for client_options.site
. First place I'd look is to see if any other omniauth plugins use a dynamic endpoint like this.
If it isn't supported, I guess the fallback would be an env variable as you described.
I'm going to submit a PR to omniauth-oauth2
first to make site
loaded the same way as the client key and secret. If that's accepted then updating the gem here should make that easier to load dynamically.
Otherwise I can submit a fallback PR here.
So would this cause our issue when we log into our app, with Sandbox accounts for testing, we're seeing the developer account in the app instead of the test account's?
- we've tried new test accounts (with their own email credentials)
- private browser sessions
- login with the sandbox URL before logging into the app
Every time, the account reverts to the developer account
A simple solution without using other strategies:
Rails.application.config.middleware.use OmniAuth::Builder do
if ENV['SALESFORCE_SCRATCH_ORG_URL'].present?
OmniAuth::Strategies::Salesforce.default_options[:client_options][:site] = ENV['SALESFORCE_SCRATCH_ORG_URL']
end
provider :salesforce, ENV['SALESFORCE_OAUTH_KEY'], ENV['SALESFORCE_OAUTH_SECRET']
end
This makes the provider still salesforce (ie auth/salesforce
, auth/salesforce/callback
) while being able to utilize scratch orgs.