Set up contact importing from dynamic subdomains
YesGraph’s invite widget uses OAuth 2.0 to get your users’ contacts from each contact importing service (I will use Google for the examples here). This authorization method requires a Redirect URL to be saved ahead of time on the Google Developer Console, and that URL must exactly match the domain initiating the authorization flow.
Trouble arises if you’d like to use the flow on a dynamic subdomain (e.g., foo.mywebsite.com, bar.mywebsite.com, etc.), because wildcard subdomains (e.g., *.mywebsite.com) are not supported on the Google Developer Console.
Here I’ll walk you through a workaround solution for initiating the auth flow from a dynamic subdomain. Let’s get started:
When the widget initiates the auth flow, it will pass the url with the dynamic subdomain (e.g., foo.mywebsite.com) to Google in a “state” parameter.
Google is going to redirect to that page, with that “state” parameter (and others) included in the hash. (e.g., www.mywebsite.com/oauth#state=foo.mywebsite.com&access_token=bar).
That page should get the url from the “state” parameter and redirect to that url, including the rest of the hash in the redirect. (e.g., foo.mywebsite.com#access_token=bar…)
YesGraph’s invite widget will handle everything from that point, so you’re done!
If you’re importing contacts from additional services (e.g., Outlook, Yahoo, etc.), you’ll only have to do this once–the flow is the same for all of them. The only thing to be aware of is that some providers will return the data not in hash parameters but in traditional url parameters (e.g., www.mywebsite.com?state=foo…), so your redirect page should be able to handle that. The code snippet included below will work for both.
Your redirect page can be very simple–users won’t be staying there long. The code here shows how to get the information you need from the URL, and redirect to the right place.
As always, feel free to drop us a line if you have any questions!