Salesforce Multi Domain Auto Login SSO

Salesforce Multi Domain Auto Login SSO

We had a use case where multiple Authentication Providers were configured for a single B2B Site.

With more than one Authentication Provider option, the User has to go through the Salesforce Login Screen to choose the correct SSO to initiate the login process. However, the ask is to automate the process based on UserType/Domains or replace the Standard login page with a custom login page.

Salesforce has an AuthConfiguration Class to retrieve authentication provider credentials for users to log in to a Salesforce org.

Request

String startUrl = '/home';
String communityUrl = 'https://xxxx.sandbox.my.site.com/Source/';
String samlId = '0LExxxxxxxxx'; //

String ssoUrl = Auth.AuthConfiguration.getSamlSsoUrl(communityUrl, startUrl, samlId);  // this will generate a link based on the SSO ID.
System.debug ('ssoUrl ' + ssoUrl);

here, we can use http/href redirect with ssoUrl.

Response

https://xxxxx.sandbox.my.site.com/Source/saml/authn-request.jsp?saml_request_id=_2CAAAAY7NOxZHMDAwMDAwMDAwMDAwMDAwAAAA-Be4IifP8x14IUjjOCqWIDQ3FiOWdS7EMcOHFE53-I_JZP0ndczZuKS8quyTn4-hAUAC3aCV2SgesIsBxJxUVMUoLPxhSv51M05K8xDjk9PXNlJME43TrJt8OQnDAZoH5wVeFre05wl5_AiuIace0FNKPdxqTWH2C7ZPyiCF-VHcX6O8YbaAQxU0JOTmmrEj_N-w5LQmYD7zsy14AVn9bcK2GiQIhivSxHv3Ka3bhUDWbC76zBh095O5kxg9z0esuw&saml_acs=https%3A%2F%2Fxxxx.sandbox.my.site.com%2FSource%2Flogin&saml_binding_type=HttpRedirect&Issuer=https%3A%2F%2Fxxxx.sandbox.my.site.com%2FSource&samlSsoConfig=0LE2h000000Cb9x&RelayState=%2Fhome

For more details refer to this link








Comments

Popular posts from this blog

Introduction to Salesforce Agent Script: Build Predictable AI Agents

Anti-Patterns in Salesforce Agentforce: What to Avoid When Building AI Agents

MCP vs. Traditional APIs: Choosing the Right Integration Approach