How To Prevent Users from Using Social Connections

Overview

This article explains how to prevent users from logging in with a social connection when there is an enterprise connection.

Applies To

  • Social Connection
  • Enterprise Connection

Solution

Using a post-login Action, it is possible to deny authentication access for users who want to use social connections instead of other methods.

  • Every user is differentiated by the connection they have signed up for.
  • Every authentication method(connection) has a boolean value of is_social.
  • This value will be true only if the user has been logged in via a social connection; otherwise, it will be false.

Here is an example of code that does not let users authenticate using a social connection.

exports.onExecutePostLogin = async (event, api) => {
  if (event.user.identities[0].isSocial){
    api.access.deny("Social connection not allowed")
  }
};