realdoug / omniauth-salesforce

OmniAuth strategy for salesforce.com
MIT License
65 stars 90 forks source link

Make site dynamic to support SFDX scratch orgs #26

Open topherlandry opened 6 years ago

topherlandry commented 6 years ago

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.

realdoug commented 6 years ago

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.

topherlandry commented 6 years ago

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.

swagner2 commented 6 years ago

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?

kriom commented 5 years ago

Perhaps my PR can help #28 ?

realdoug commented 5 years ago

@kriom thanks for contributing. Will take a look this week.

adimasuhid commented 5 years ago

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.