Configuring the registration handler should be completed by someone with an understanding of Apex, Salesforce SSO, and your identity provider. Below is a sample approach for a simplified implementation using the default template. This should not be used for production as it may not meet your specific needs. We encourage testing to validate that your registration handler is configured correctly. This is not a definitive guide on how to customize the registration handler.
-
To update the Apex code, in the newly created Auth. Providers window click the link next to Registration Handler to open the Apex classes window.
-
Click Edit and change the generate Global Class name to something more meaningful to you such as
IdentityServiceRegistrationHandler.The generated name will be something like
AutocreatedRegHandler1624989012775. -
Comment out all references to the method
canCreateUser(Auth.UserData data).If the method references are not commented out, you will not be able to log in through your provider because a new user will not be created. The method is
falseby default. -
In the
createUsermethod, change the value of the string@myorg.comto be the email domain as specified in your identity provider within the section where a standard user object is instantiated. To do this within the Apex code:- Find
u.username = data.username + '@myorg.com'and add your domain instead. - If your providers username is formated as an email address, change the line to be
u.username = data.username.
- Find
Note
In the example above, a new Salesforce user is created at login through your provider. If you are attempting to match an existing Salesforce user, the same createUser method is called, but the Registration Handlers Apex code should be updated to use some combination of identifiable values from your provider to query Salesforce to find user values to identify, and return an existing user instead of attempting to create a new user.
Note
You can configure the Apex code in lots of different ways to suit your organization. See the Salesforce documentation for more information: