This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

How To: Login to Salesforce with Facebook

This topic provides instructions on how to log into Salesforce using your WSO2 Identity Server credentials.

Configuring Salesforce

  1. Sign up as a Salesforce developer.
    1. Fill out the relevant information found in the following URL: https://developer.salesforce.com/signup
    2. Click Sign me up.
    3. You will receive a security token by email to confirm your new account. If you did not receive the email successfully, you will be able to reset it by following the steps given here.
  2. Log in with your new credentials as a Salesforce developer. Do this by clicking Login link in the top right hand side of https://developer.salesforce.com/.
  3. Click Allow to enable Salesforce to access your basic information.
  4. Once you are logged in, create a new domain and access it. 

    Tip: This step is required only if the validation request is sent by the service provider. For identity provider initiated validation requests, this is not required.

    To do this, do the following steps.

    1. Go to Domain Management in the left navigation pane and click My Domain.
    2. In the page that appears, come up with a name for your domain. You can check if the domain is available by clicking the Check Availability button.
    3. Check and agree with the Terms and Conditions before clicking Register Domain to register your new domain.

      Tip: The registration process may take some time. Use this time to get familiar with Salesforce and read through the Salesforce developer documentation.

    4. Once the domain is registered to your account, click the Click here to login button to test this out.
  5. On the left navigation menu, go to Security Controls and click Single Sign-On Settings.
  6. In the page that appears, click Edit and then select the SAML Enabled checkbox to enable federated single sign-on using SAML.
  7. Click Save to save this configuration change.
  8. Click New under SAML Single Sign-On Settings. The following screen appears. 
    Ensure that you configure the following properties.

    FieldValue
    NameSSO
    API NameSSO
    Issuer

    localhost

    Note: In this case we have localhost as the Issuer as this topic is a sample of how this should work. In a production environment where you need to run this scenario, you must have the domain name or host name of the server that you are hosting the WSO2 Identity Server.

    Entity Idhttp://saml.salesforce.com
    Identity Provider Certificate

    wso2.crt

    Note: To create the Identity Provider Certificate, open your Command Line interface, traverse to the <IS_HOME>/repository/resources/security/ directory. Next you must execute the following command.

    Keytool -export -alias wso2carbon -file wso2.crt -keystore wso2carbon.jks -storepass wso2carbon

    Once this command is run, the wso2.crt file is generated and can be found in the <IS_HOME>/repository/resources/security/ directory. Click Choose File and navigate to this location in order to obtain and upload this file.

    Request Signing CertificateFrom the dropdown, you must select the public certificate of Salesforce. If you have not created this already, check step 15 of this section for details on how to create the certificate.
    Request Signature MethodRSA-SHA1
    Assertion Decryption CertificateAssertion not encrypted
    SAML Identity Type

    Assertion contains User's salesforce.com username

    SAML Identity Location

    Identity is in the NameIdentifier element of the Subject statement

    Identity Provider Login URL

    https://localhost:9443/samlsso

    Note: In this case we have localhost as the URL as this topic is a sample of how this should work. In a production environment where you need to run this scenario, you must have the domain name or host name of the server that you are hosting the WSO2 Identity Server.

    Identity Provider Logout URL

    https://localhost:9443/samlsso

    Note: In this case we have localhost as the URL as this topic is a sample of how this should work. In a production environment where you need to run this scenario, you must have the domain name or host name of the server that you are hosting the WSO2 Identity Server.

    Custom Error URLLeave blank

    Service Provider Initiated Request Binding

    HTTP POST
    User Provisioning EnabledLeave blank
  9. Click Save to save your configurations.
  10. Go to Domain Management in the left navigation pane and click My Domain.
  11. Click Deploy to Users. Click Ok to the confirmation message that appears.
  12. In the page that appears, you must configure the Authentication Configuration section. Scroll down to this section and click Edit.
  13. Under Authentication Service, select SSO instead of Login Page.
  14. Click Save.
  15. Next you need to obtain the Salesforce certificate and upload it to the Identity Server.

    About the Salesforce certificate

    The validation request sent from Salesforce must be validated by the Identity Server. For this purpose, the Salesforce public certificate must be uploaded to the Identity Server and is used to validate the request.

    Do the following steps to obtain the certificate.

    1. On the left navigation menu, go to Security Controls and click Certificate and Key Management.
    2. If you have not done so already, you must create the certificate first. Do the following steps to create this.
      1. Click Create Self-Signed Certificate.
      2. Enter the Label and a Unique Name and click Save. The certificate is generated.
    3. Click the Download Certificate button to download the certificate.

Configuring the service provider

  1. Sign in. Enter your username and password to log on to the management console
  2. Navigate to the Main menu to access the Identity menu. Click Add under Service Providers.
  3. Fill in the Service Provider Name and provide a brief Description of the service provider. Only Service Provider Name is a required field and we use Salesforce as the name for this example.
  4. Click Register.
  5. Expand the Inbound Authentication Configuration and the SAML2 Web SSO Configuration and click Configure.
  6. In the form that appears, fill out the following configuration details required for single sign-on.

     See the following table for details.

    FieldValueDescription
    Issuerhttps://saml.salesforce.comThis is the <saml:Issuer> element that contains the unique identifier of the service provider. This is also the issuer value specified in the SAML Authentication Request issued by the service provider. When configuring single-sign-on across Carbon servers, ensure that this value is equal to the ServiceProviderID value mentioned in the <IS_HOME>/repository/conf/security/authenticators.xml file of the relying party Carbon server.
    Assertion Consumer URLhttps://identityprovisioning-dev-ed.my.salesforce.com?so=00D90000000ySEnThis is the URL to which the browser should be redirected to after the authentication is successful. This is the Assertion Consumer Service (ACS) URL of the service provider. The identity provider redirects the SAML2 response to this ACS URL. However, if the SAML2 request is signed and SAML2 request contains the ACS URL, the Identity Server will honor the ACS URL of the SAML2 request. In this case, you must use your Salesforce login URL. In Salesforce, click Security Controls on your left menu and then click Single Sign-On Settings. In the page that appears, click on the SSO settings that you created to view the details. Use the Salesforce Login URL listed there for this value.
    NameID FormatThe default value can be used here.This defines the name identifier formats supported by the identity provider. The service provider and identity provider usually communicate with each other regarding a specific subject. That subject should be identified through a Name-Identifier (NameID) , which should be in some format so that It is easy for the other party to identify it based on the format. Name identifiers are used to provide information regarding a user.
    Enable Response SigningSelected

    Select Enable Response Signing to sign the SAML2 Responses returned after the authentication process.

    Enable Attribute ProfileSelectedSelect Enable Attribute Profile to enable this and add a claim by entering the claim link and clicking the Add Claim button. The Identity Server provides support for a basic attribute profile where the identity provider can include the user’s attributes in the SAML Assertions as part of the attribute statement. Once you select the checkbox to Include Attributes in the Response Always, the identity provider always includes the attribute values related to the selected claims in the SAML attribute statement.
  7. Click Register to save your configurations.
  8. Since Salesforce user names are actually email addresses, we must configure the Identity Server for email authentication. Do the following steps to achieve this.

    1. Open the <IS_HOME>/repository/conf/carbon.xml file and make the following change to the configuration.

      <EnableEmailUserName>true</EnableEmailUserName>
    2. Open the <IS_HOME>/repository/conf/user-mgt.xml file and add the following property under the user store manager configurations. Using above property, you can change the pattern of your email address. By default it must be more than 3 characters and less than 30, but you can configure it as you wish.

      <Property name="UsernameWithEmailJavaScriptRegEx">^[\S]{3,30}$</Property>
  9. Restart the Identity Server. 

Configuring the Facebook app

  1. Go to https://developers.facebook.com/ and log in using your Facebook credentials.
  2. Navigate to the window where you can create a new app by clicking Add a New App under the Apps menu. 
  3. Choose the platform you wish to use. Select Website here when working with this sample.
  4. Enter the name of your new app in the window that appears and click Create New Facebook App ID.

    Add the relevant website details by pointing to https://localhost:9443/ and click Next.
     
  5. Click Skip to the Developer Dashboard to access the dashboard.
  6. This will take you to the app Dashboard where you can find the App ID and App Secret as shown in the image below. Click Show to view the App Secret.
  7. Click Settings on the left menu and navigate to the Advanced section by clicking on the tab at the top of your screen. Here you need to configure the OAuth Settings.
    Make the following changes:

    1. Client OAuth Login should be set to Yes.
    2. Valid OAuth redirect URIs should be set to https://localhost:9443/commonauth.

      Note: In a production environment where you need to run this scenario, you must have the domain name, host name or IP address of the server that you are hosting the WSO2 Identity Server instead of localhost.

  8. Click the Save Changes button to save the changes. 

Now you have finished configuring Facebook as an Identity Provider.

About accessing the app

The app is not available to general public yet. To make to app available to every Facebook user, you have to submit the app for review. After a review, Facebook makes the app available to every Facebook user. You can find more information on the review process by clicking on Status and Review in the left navigation menu of your app's dashboard.

The review process may take some time, so for the purposes of this sample, you can specify some Facebook users as Developers or Testers. Only the users specified here can use this app to log in with Facebook until the app goes public. To do this, click on Roles in the left navigation menu of the dashboard and specify the required Facebook users as Developers or Testers.

Configuring the identity provider

Now you have to configure WSO2 Identity Server by adding Facebook as a new identity provider.

  1. Log in to the management console as an administrator.
  2. In the Identity section under the Main tab of the management console, click Add under Identity Providers.
  3. Give a suitable name as the Identity Provider Name. In this case we can have Facebook as the identity provider name for clarity.
  4. Go to Facebook Configuration under Federated Authenticators

  5. Enter the App ID and App Secret values from the Facebook app you created in the Client Id and Client Secret fields respectively.
     

  6. Select both checkboxes to Enable Facebook Authenticator and make it the Default.

  7. Click Register. 

You have now added the identity provider.

Configuring the federated authenticator for the service provider

The next step is to configure the federated authenticator for the service provider. In this case, the service provider is Salesforce

  1. Return to the management console.
  2. In the Identity section under the Main tab, click List under Service Providers.
  3. Go to the service provider that you created and click Edit.
  4. Go to Local and Outbound Authentication Configuration section.

  5. Select the Identity Provider you created from the dropdown list under Federated Authentication

  6. Ensure that the Federated Authentication radio button is selected and select Facebook from the dropdown. This is the name of the identity provider that you configured.

  7. Click Update to save the changes.

You have now added the identity provider as the federated authenticator for Salesforce.

Configuring claim mapping for Facebook

The next step is to configure claims in the Identity Server and map them with Facebook.

  1. In the Identity section under the Main tab, click List under Identity Providers.
  2. Click Edit to edit the Facebook identity provider you created. 
  3. Under Claim Configuration, go to Basic Claim Configuration.
  4. Select the Define Custom Claim Dialect option under Select Claim mapping Dialect
  5. Click Add Claim Mapping to add custom claim mappings as follows.
    Do the following mappings as shown in the above screenshot.

    Identity Provider Claim URILocal Claim URIDescription
    emailhttp://wso2.org/claims/emailaddressHere we map the value in Facebook with the claim URI in the Identity Server. In this case it is a direct correlation of claims where the email attribute of Facebook users is mapped to the email attribute used in the Identity Server.
    first_namehttp://wso2.org/claims/givennameHere we map the value in Facebook with the claim URI in the Identity Server. In this case it is a direct correlation of claims where the first_name attribute of Facebook users is mapped to the givenname attribute used in the Identity Server.
    last_namehttp://wso2.org/claims/lastnameHere we map the value in Facebook with the claim URI in the Identity Server. In this case it is a direct correlation of claims where the last_name attribute of Facebook users is mapped to the lastname attribute used in the Identity Server.

    You can retrieve all the public information of the user and the email address. The following are some common attribute names.

    id
    email
    name
    first_name
    last_name
    link
    gender
    locale
    age_range

    More information is available from the following link: https://developers.facebook.com/docs/facebook-login/permissions/v2.0

    You can map these attributes to any Local Claim URI that is suitable.

Configuring claim mapping for Salesforce

  1. In the Identity section under the Main tab, click List under Service Providers.
  2. Click Edit to edit the Salesforce service provider you created. 
  3. Expand the Claim Configuration section.
  4. Select the Define Custom Claim Dialect option under Select Claim mapping Dialect.
  5. Click Add Claim URI to add custom claim mappings as follows.
    Add the following claim URIs.

    Service Provider ClaimLocal Claim
    emailhttp://wso2.org/claims/givenname
    first_namehttp://wso2.org/claims/emailaddress
    last_namehttp://wso2.org/claims/lastname

    Also do the following changes.

    1. Select all of these claims as requested claims using the checkboxes provided.
    2. Select email from the Subject Claim URI dropdown. The Subject Claim URI is important to define as it is the unique value used to identify the user. In cases where you have a user store connected to the Identity Server, this Subject Claim URI value is used to search for the user in the user store.
  6. Click Update to save your changes.

Testing the configurations

Do the following steps to test out the configurations for a new user in Salesforce and the Identity Server.

  1. Once you log into the Identity Server, navigate to the Main menu in the management console, click Add under Users and Roles.
  2. Click Users. This link is only visible to users with the Admin role. 
  3. Click Add New UserWhen adding a new user, use the same credentials as the Facebook user. You must use an email address as the username.
  4. Click Finish.
  5. Log back into your Salesforce developer account.
  6. On the left navigation pane, click Users under Manage Users.
  7. On the page that appears, click the New User button to create a new user.
  8. Create a user with the same credentials as the one you created in the Identity Server. This will also be the same as your Facebook user. Click Save to save your changes. An email will be sent to the email address you provided for the user.
  9. Logout of Salesforce and log back in using the newly created user's credentials sent via the email.
  10. Set the password to the same value you had in the Identity Server and Facebook and log out again.
  11. Access your Salesforce login URL. For this example, the Salesforce login URL is https://identityprovisioning-dev-ed.my.salesforce.com?so=00D90000000ySEn. You are directed to the Facebook Login screen if you are not already logged in.
  12. Log in using your Facebook credentials. You are then redirected back to Salesforce.