You are here:
Configure the Auth Provider in the Sandbox Org
Before you begin, have the consumer key and secret generated by the external client available for the B2C Commerce Merchant Agent.
-
In the Salesforce sandbox org, create the Registration Handler Apex Class.
-
At the top of the page, click
and select Setup.
- In the Quick Find box, enter Apex Classes, and then select Apex Classes.
- Click New.
-
Create the B2CRegistrationWrapper class by copying and pasting the following code
in the class editor.
global class B2CRegistrationWrapper implements Auth.RegistrationHandler { /** * Instantiates the standard B2C Commerce handler to delegate the logic. */ private Auth.B2CCommerceCloudRegistrationHandler getStandardHandler() { return new Auth.B2CCommerceCloudRegistrationHandler(); } global User createUser(Id portalId, Auth.UserData data) { // You can add custom pre-processing logic here // Delegate to the standard handler return getStandardHandler().createUser(data); } global void updateUser(Id userId, Id portalId, Auth.UserData data) { // You can add custom logging or attribute mapping here // Delegate to the standard handler getStandardHandler().updateUser(userId, data); } }
-
At the top of the page, click
-
Save your changes.
This Apex class acts as a wrapper around the standard B2C Commerce registration handler. You can add custom pre-processing logic or attribute mappings as needed.
- In the Quick Find box, enter Auth Providers, and then select Auth Providers.
- Click New.
-
Configure the Auth Provider by entering the field values in the following table.
Field Value Provider Type Salesforce Name Enter a descriptive name for the Auth Provider. Consumer Key From the Salesforce IdP org, navigate to the External Client App, select the Settings tab, and then locate the Consumer Key in OAuth Settings. Consumer Secret From the Salesforce IdP org, navigate to the External Client App, select the Settings tab, and then locate the Consumer Secret in OAuth Settings. Authorize Endpoint URL https://idp-org-hostname/services/oauth2/authorize Token Endpoint URL https://idp-org-hostname/services/oauth2/token Registration Handler Type Apex Registration Handler B2CRegistrationWrapper class Execute Registration As Select a user with the System Administrator role - Click Save.
-
Copy the generated Callback URL.
The Auth Provider also generates a single sign-on URL for users to access the sandbox org.
- Log in to the primary IdP org and open the external client app that you created earlier.
- Paste the Callback URL into the external client app's Callback URL field.
- Save the changes.

