Skip to main content


BlokSec can be configured as an inbound federation identity provider (a.k.a. social provider) for your Salesforce tenant, and can also be integrated to support just in time provisioning (JIT) for user creation in Salesforce. The following article describes the process to configure authentication and provisioning to support passwordless Salesforce login.

BlokSec Admin UI

  1. Sign into BlokSec admin UI as a user with admin privileges for your tenant

  2. On the main dashboard, click the Add Application drop-down and select Create From Template and then select Salesforce

  3. Complete the application details as follows :

    • Name: Default is set to Salesforce (or your desired application name – we will assume this is called ‘Salesforce’ for the remainder of this article)

    • Logo URI: Loation of the image URL (For example :

    • Backgroun URI: Location of the brackground image URL (For example :

    • Session Length: Length of the authenticated session. Default value is set to 60 minutes

    • Redirect URIs: (leave blank for now)

    • Post Logout Redirect URIs: (leave blank for now)

    • Select Submit to save the configuration

  4. Click Generate App Secret, and make note of the Application ID and Application Secret as these will be required when registering your application with Salesforce

Salesforce Admin UI

Registration Handler Configuration

  1. Sign into the Salesforce as a user with admin privileges for your tenant

  2. Navigate to Platform Tools > Custom Code

  3. Select Apex Classes and then choose New and add the following to the Apex Class tab:

//TODO: You will need to customize this class to ensure it meets your needs and
//the data provided by the third party.

global class BlokSecRegHandler implements Auth.RegistrationHandler{
global boolean canCreateUser(Auth.UserData data) {
System.debug('canCreateUser was called for ' + (data != null ? data.username : 'null'));
Boolean retVal = (data != null
&& != null
&& data.lastName != null
&& data.firstName != null
&& data.username != null);


return retVal;

global User createUser(Id portalId, Auth.UserData data){
System.debug('createUser was called for portalId: ' + portalId + ' and userName: ' + data.username);

User u;

List<User> l = [SELECT Id,UserName,FirstName,LastName,Email FROM User WHERE UserName = :data.username];
if (l.size() > 0)
u = l[0];
System.debug('Found existing user record for '+ data.firstName + ' ' + data.lastName + ' ' +;
System.debug(u.FirstName + ' ' + u.LastName + ' ' + u.Email + ' ' + u.UserName);

// Update existing record
u.Email =;
u.LastName = data.lastName;
u.FirstName = data.firstName;

System.debug('Updating user record for '+ data.firstName + ' ' + data.lastName + ' ' +;
System.debug(u.FirstName + ' ' + u.LastName + ' ' + u.Email);

return u;

// If the user was not found, we will create a new one
// First check that the required data was provided
if(!canCreateUser(data)) {
System.debug('canCreateUser returned false; aborting SSO flow');
//Returning null or throwing an exception fails the SSO flow
return null;
//The user is authorized, so create their Salesforce user
u = new User();
Profile p = [SELECT Id FROM profile WHERE name='Chatter Free User'];
//TODO: Customize the username. Also check that the username doesn't already exist and
//possibly ensure there are enough org licenses to create a user. Must be 80 characters
//or less.
u.username = data.username; = data.username;
u.lastName = data.lastName;
u.firstName = data.firstName;
String alias = data.username;
//Alias must be 8 characters or less
if(alias.length() > 8) {
alias = alias.substring(0, 8);
u.alias = alias; = data.username;
u.localesidkey = UserInfo.getLocale();
u.languagelocalekey = 'en_US';
//u.localesidkey = UserInfo.getLocale();
u.emailEncodingKey = 'UTF-8';
u.timeZoneSidKey = 'America/Los_Angeles';
u.profileId = p.Id;
return u;

global void updateUser(Id userId, Id portalId, Auth.UserData data){
System.debug('The userid is: ' + userId);
System.debug('The Auth.UserData is: ' + data);
User u = new User(id=userId); =;
u.lastName = data.lastName;
u.firstName = data.firstName;
u.username = data.username;
  1. Click Save

OIDC Configuration

  1. Sign into the Salesforce as a user with admin privileges for your tenant

  2. Navigate to Settings > Identity

  3. Select Auth. Providers and then choose New

  4. Select Open ID Connect from the dropdown menu and complete the authentication provider configuration with the following values (adjusting if required to meet your desired behaviour):

    • Name: Salesforce Passwordless Login (or the name of your choice)

    • URL Suffix: Keep the auto generated value or update it to meet your requirements

    • Consumer Key: (the Application ID captured from the BlokSec admin UI above)

    • Consumer Secret: (the Application Secret captured from the BlokSec admin UI above)

    • Authorize Endpoint URL:

    • Token Endpoint URL:

    • User Info Endpoint URL:

    • Default Scopes: openid email profile

    • Send access token in header: selected / checked

    • Include Consumer Secrets in API Responses: selected / checked

    • Custom Logout URL:

    • Registration Handler: BlokSecRegHandler (use registration handler lookup)

    • Execute Registration As: (choose a user / account that has the ability to create / update / delete users)

    • Select Save to accept configuration changes

  5. Once saved, navigate to the Salesforce configuration section and copy the values for the following URL’s:

    • Callback URL

    • SingleLogout URL


Authentication Configuration

  1. Sign into the Salesforce as a user with admin privileges for your tenant

  2. Navigate to Settings > Company Settings

  3. Select My Domain and then navigate to Authentication Configuration section

  4. Select Edit and then select / check the name of the Authentication Service created above in OIDC configuration, for example, Salesforce Passwordless Login

  5. Select Save

BlokSec Admin UI (Part 2)

  1. Return to the Salesforce application configuration, click the gear in the upper-right, and select Edit Application

  2. Input the value of the CallBackURL into BlokSec Redirect URI field as defined by Salesforce in last step of OIDC configuration

  3. Input the value of SingleLogout URL into BlokSec Post Logout Redirect URIs field as defined by Salesforce in last step of OIDC configuration

  4. Select Submit to save the configuration