How to use a custom client ID for authentication

#Overview

With some CRMs, WP Fusion is registered as an app via those platforms’ developer programs. Because of this, you need an account on our site and a WP Fusion license to complete the initial authentication process with your CRM.

This applies to:

  • BirdSend
  • Drift
  • HubSpot
  • NationBuilder
  • Salesforce
  • Zoho

There may be scenarios where you want to use your own client ID for authentication, and not the WP Fusion client ID. For example if you have a created a custom branded app via your CRM’s developer program, or if you don’t have a WP Fusion license.

#Using a custom client ID and authorization URL

The client ID and client secret are public properties on each CRM’s integration class. You can override them by hooking into the wp_fusion_init_crm action, which passes the CRM object by reference.

For example with Zoho:

function set_custom_zoho_app( &$crm ) {

	$crm->client_id        = '1000.XXXXXXXXXXXXXXXXXXXXX';
	$crm->client_secret_us = '08dccXXXXXXXXXXXXXXXXXXXXX';

}

add_action( 'wp_fusion_init_crm', 'set_custom_zoho_app' );

To override the initial authorization request URI for the “Authorize” button in the WP Fusion settings, use the wpf_{$crm}_auth_url filter, for example with Zoho:

function set_custom_zoho_auth_url() {

	return "https://accounts.zoho.com/oauth/v2/auth?scope=ZohoCRM.modules.ALL,ZohoCRM.settings.ALL,ZohoCRM.users.READ,ZohoCRM.org.READ &response_type=code&access_type=offline&redirect_uri=https%3A%2F%2Fmysite.com%2Fzoho.php&prompt=consent&client_id=XXXX";

}

add_action( 'wpf_zoho_auth_url', 'set_custom_zoho_auth_url' );

Note that in this example you must have registered https://mysite.com/zoho.php as the redirect URI for your app, and must have a script running at that location which is capable of listening for the authorization response and redirecting back to the WP Fusion settings page with the &code= parameter in the URL.

#HubSpot example

To set your own custom HubSpot client ID, secret, and app ID:

function set_custom_hubspot_app( &$crm ) {

	$crm->client_id     = '959bd865-5a24-4a43-a8bf-XXXXXXXXXXXX';
	$crm->client_secret = '959bd865-5a24-4a43-a8bf-XXXXXXXXXXXX';
	$crm->app_id        = 123456;

}

add_action( 'wp_fusion_init_crm', 'set_custom_hubspot_app' );

To override the initial OAuth authorization URL on the “Authorize with HubSpot” button:

function set_custom_hubspot_auth_url() {

	$args = array(
		'client_id'     => wp_fusion()->crm->client_id,
		'redirect_uri'  => admin_url( 'options-general.php?page=wpf-settings&crm=hubspot' ),
		'scope'         => 'contacts automation oauth e-commerce crm.lists.read crm.objects.contacts.read crm.objects.contacts.write crm.schemas.contacts.read crm.lists.write crm.objects.companies.read crm.objects.deals.read crm.objects.deals.write crm.schemas.companies.read crm.schemas.deals.read crm.objects.owners.read',
	);

	$url = add_query_arg( $args, 'https://app.hubspot.com/oauth/authorize' );

	return $url;

}

add_action( 'wpf_hubspot_auth_url', 'set_custom_hubspot_auth_url' );

#Salesforce example

To set your own custom Salesforce client ID and secret:

function set_custom_salesforce_app( &$crm ) {

	$crm->client_id     = '3MVG9CEn_O3jvv0xMf5rhesocm_5czidz9CFtu_qNZ2V0Zw.bmL0LTRRylD5fhkAKYwGxRDDRXXXXXXXXXXXX';
	$crm->client_secret = '9BB0BD5237B1EA6ED8AFE2618053XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';

}

add_action( 'wp_fusion_init_crm', 'set_custom_salesforce_app' );

To override the initial OAuth authorization URL:

function set_custom_salesforce_auth_url() {

	$args = array(
		'client_id'     => wp_fusion()->crm->client_id,
		'redirect_uri'  => admin_url( 'options-general.php?page=wpf-settings&crm=salesforce' ) ),
		'response_type' => 'code',
		'scope'         => 'api refresh_token offline_access',
	);

	$url = add_query_arg( $args, 'https://login.salesforce.com/services/oauth2/token' );

	return $url;

}

add_action( 'wpf_salesforce_auth_url', 'set_custom_salesforce_auth_url' );

 

Was this helpful?