Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Salesforce Marketing Cloud strategy and dynamically setting the client_options.token_url ? #1054

Open
popcorn opened this issue Jan 14, 2022 · 4 comments

Comments

@popcorn
Copy link

popcorn commented Jan 14, 2022

Hi there, as the subject says, is there a way to dynamically set the URL on which we request tokens?

Why?

I'm creating an OAuth integration for Salesforce Marketing Cloud (SFMC).

Every customer on SFMC gets their own domain that has to be used for API calls, and for requesting tokens. This domain is returned alongside code and state parameters when the customer authorizes my app.

From SFMC docs:

Your application receives the customer’s Marketing Cloud subdomain, or tssd, and an authorization code after the customer has authorized your application by logging in to Marketing Cloud, as part of the authorization code grant type for web app integrations. When you request a token on the customer’s behalf, you must use the customer’s subdomain, or tssd

Is there a way to take the tssd parameter (customer subdomain) from the authorization response and use it as an URL on which I request the tokens?

@simonwh
Copy link

simonwh commented Aug 20, 2022

@popcorn Hi! Did you get any further with your SFMC omniauth provider? :)

@popcorn
Copy link
Author

popcorn commented Aug 20, 2022

@popcorn Hi! Did you get any further with your SFMC omniauth provider? :)

Hey, we put the SFMC integration on the backburner for now.

You?

@simonwh
Copy link

simonwh commented Aug 20, 2022

@popcorn Ended up writing small subclass to https://github.com/omniauth/omniauth-oauth2, putting it in my local lib folder and using that. That part was pretty straight forward. Regarding what you asked below, you have to use the https://github.com/omniauth/omniauth/wiki/Dynamic-Providers approach. I had a similar, but not exact same, situation. Users enter their subdomain, client_id and client_secret in my app and I have to redirect to the correct domains etc.

Ended up with something along the lines of:

provider :salesforce_marketing_cloud,
  setup: lambda { |env|
    request         = ActionDispatch::Request.new(env)

    integration_id = env['rack.session'][:auth_integration_id]
    integration = Integration.find(integration_id)

    if integration.is_a? SalesforceMarketingCloudIntegrationV2
      env['omniauth.strategy'].options.merge!(
        {
          client_id:       integration.settings['client_id'],
          client_secret:   integration.settings['client_secret'],
          scope:           'saved_content_read saved_content_write documents_and_images_read documents_and_images_write email_read email_write offline',
          client_options: {
            authorize_url: "https://#{integration.settings['subdomain']}.auth.marketingcloudapis.com/v2/authorize",
            token_url: "https://#{integration.settings['subdomain']}.auth.marketingcloudapis.com/v2/token",
            site: "https://#{integration.settings['subdomain']}.auth.marketingcloudapis.com"
          }
        }
      )
    end
  }

Hope it can be of some use!

@popcorn
Copy link
Author

popcorn commented Aug 20, 2022

That's great! I may ask you a few more questions about it when we continue working on the SFMC integration again.

Feels less lonely now knowing someone else went through same struggles with SFMC 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants