Newer Version Available
MyDomainLoginDiscoveryHandler Interface
Namespace
Usage
Implement MyDomainLoginDiscoveryHandler to let My Domain users log in with something other than their username and password. This handler contains the logic to look up the user based on the identifier value entered on the login page. The Auth.MyDomainLoginDiscoveryHandler.login method is invoked when the identifier page is submitted and finds the user that corresponds to the submitted identifier. The Auth.SessionManagement.finishLoginDiscovery method sends the user to the authentication mechanism and then logs in the user.
Register the handler from the My Domain Setup page. Under Authentication Configuration, select the Discovery Login Page Type. For Login Discovery Handler, select this handler from the list of Apex classes.
For an example, see MyDomainLoginDiscoveryHandler Example Implementation. For more details, search for My Domain Login Discovery in Salesforce Help.
MyDomainLoginDiscoveryHandler Method
MyDomainLoginDiscoveryHandler has the following method.
login(identifier, startUrl, requestAttributes)
Signature
public System.PageReference login(String identifier, String startUrl, Map<String,String> requestAttributes)
Parameters
- identifier
- Type: String
- Identifier the Salesforce user entered at the login prompt, for example, an email address or phone number.
- startUrl
- Type: String
- The page users see after successfully logging in to the My Domain subdomain.
- requestAttributes
- Type: Map <String, String>
- Information about the login request based on the user’s browser state when accessing the login page. requestAttributes passes in the MyDomainUrl, IpAddress, UserAgent, Platform, Application, City, Country, and Subdivision values. The City, Country, and Subdivision values come from IP address geolocation.
Return Value
Type: System.PageReference
The URL of the page where the user is redirected to complete authentication.
Example
Here’s a sample requestAttributes response.
MyDomainLoginDiscoveryHandler Example Implementation
Here's an example of the Auth.MyDomainLoginDiscoveryHandler interface. This sample class contains the default logic for My Domain login discovery using password authentication. You can customize the code to ensure it meets your needs. The requestAttributes parameter provides additional information that you can use in the discovery logic. Attributes include MyDomainUrl, IpAddress, UserAgent, and location information (such as Country and City). Use Auth.DiscoveryCustomErrorException to throw custom errors to display on the login page.
To implement this interface, the My Domain login page type must be set to Discovery.
Test Class for MyDomainDiscLoginDefaultHandler Class
The following is the test class for MyDomainDiscoveryLoginHandler. For the test to work, your org must have the My Domain login page type set to Discovery.