0

We're setting up SSO for our community. It currently works, in that if the user goes to the standard Salesforce login page they are presented with an option log in via SSO.
Which is cool.

But I want them to be able to log in via my custom Angular app sitting on a Visualforce page.

The function executed by the login via SSO button is something like this:

IdpOptions.useIdp(
'SingleSignOnName', 
'https://myInstance.force.com/api/saml/authn-request.jsp?saml_request_id=[SAML request Id]&saml_acs=[login url]&saml_binding_type=HttpPost&Issuer=https%3A%2F%2FmyInstance.my.salesforce.com&samlSsoConfig=[configId]&RelayState=[relayState]'
);

How do I construct that in code? Javascript, Apex, Visualforce voodoo, I don't care which. Whatever it takes for me to generate that link with all the parameters for the user to log in via our custom app.

Here's what I have so far:
The missing components to that url are:

  • SAML request Id
  • login url
  • configId
  • relayState

The login url itself has 2 paramters:

  • org Id
  • configId

I can store the configId in a custom setting (get it from the url of the Single Sign-On Setting in Setup). Same goes for the org id.
The relayState is just the redirect location after the user is logged in.

So all I'm really looking for is how to generate the SAML request Id. I'm still not entirely sure what it is.

0

I was doing it wrong.
I need to use the AuthConfiguration class in the Auth namespace.
Let's break it down.

Visualforce page

<apex:form id="ssoLoginForm">
    <apex:actionFunction name="ssoLogin" action="{!loginSSO}" rerender="loginFailedVar">
    </apex:actionFunction>
</apex:form>
<apex:outputText id="loginFailedVar" value="{!loginFailed}"></apex:outputText>  

That gives us a javascript function on window that we can call from our Angular app.
window.ssoLogin();
(It also sets up a nice way to notify the user that something went wrong, but not relevant here).
The javascript function calls the following function in the controller.

Apex controller

public PageReference loginSSO(){
    String startUrl = '/startPage';
    String communityUrl = 'https://my-community.force.com';
    String samlId = '0LEXXXXXXXXXXXX'; //This is the configId I mentioned in my question
    String ssoUrl = Auth.AuthConfiguration.getSamlSsoUrl(communityUrl, startUrl, samlId);
    PageReference pageRef = new PageReference(ssoUrl);
    return pageRef;
}

And that's it. No need to futz around with building links client-side using compressed forms of the SAML request. Just do it in Apex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.