Skip to content

Single Sign-On

Overview

Single Sign-On (SSO) allows Informat to use third-party authentication services to authenticate users. There are two authentication processes:

  • Initiated from the Informat login page: After the user enters their account and password, a third-party system is called for authentication.
  • Initiated from a third-party system page: Informat API is called for authentication.

SSO Process

Initiated from Informat Login Page

Trigger timing: Triggered after the user enters their account and password. Configuration conditions:

  • In a newly created or existing application, find Application Design -> Scripts, and create a systemhook.js file (the script name can be customized). Implement the sso method in the systemhook.js file to handle authentication business logic.
javascript
export function login(ctx) {
  console.log("ctx parameters:", ctx.userName, ctx.password, ctx.ip, ctx.type);
  //todo authentication
  return {
    success: true,
  };
}
  • Login function input parameter ctx

    idDescription
    userNameUser name (may be phone number or email)
    passwordPassword
    ipIP address
    typeLogin type index,mobile
  • Login function return value

    idDescription
    successWhether authentication was successful
    messageError message, can be omitted if successful
  • Find and set the following parameters in the Informat management backend (/guide/admin) -> System Information -> Parameter Settings:

    • System Hook Application ID
    • Data storage database index of the team to which the system hook application belongs
    • System Hook Script Path
    • SSO login function initiated from the Informat login page
    • SSO login function initiated from a third-party page

TIP

system.systemHookDbIndex Set to 0 if there is only one business database

How to find the application ID from the first step? Find the Application Management button on the workbench

Click the Application Management button, find the application from the first step in the application list, then click Settings

Find the appid in the application information

  1. system.systemHookScriptPath Enter the script path created in the first step (systemhook.js)

Example: Single Sign-On with LDAP Authentication

javascript
export function login(ctx) {
  console.log("ctx", ctx.userName, ctx.password, ctx.ip, ctx.type);
  // const success=informat.user.passwordAuth(ctx.userName,crx.password);
  const userName = ctx.userName;
  const password = ctx.password;
  let connection = null;
  try {
    connection = informat.ldap.connect({
      providerURL: "LDAP://1.13.173.190:389",
      securityPrincipal: userName,
      securityCredentials: password,
    });
  } catch (e) {
    //Connection to LDAP server or authentication failed
    console.error("ldap login failure:", userName);
    return {
      success: false,
      message: "Login failed", //Login failure message
    };
  } finally {
    if (connection != null) {
      connection.close();
    }
  }
  return {
    success: true,
  };
}

SSO Initiated from Third-Party Page

SSO login process:

  • Third-party service makes an HTTP request to the Informat SSO service address: https://next.informat.cn/account/main/sso
  • Informat SSO service calls the sso function for authorization

In a newly created or existing application, find Application Design -> Scripts, and create a systemhook.js file (the script name can be customized). Implement the sso method in the systemhook.js file to handle business logic before authorization.

javascript
export function sso(ctx) {
  console.log("ctx parameters:", ctx);
  //TODO authenticate to get accountId
  return {
    accountId: "x38s0fa436v69",
    success: true,
    redirectUrl: "/workbench/app",
  };
}
  • SSO function input parameter ctx
PropertyTypeDescription
headersObjectHTTP request headers
cookiesObjectHTTP cookies
queryObjectQuery parameters
bodyStringHTTP request body
urlStringHTTP request URL
pathStringPath
methodStringRequest method
ipStringIP address
  • SSO function return value
PropertyTypeDescription
accountIdStringAuthorized account ID
successBooleanWhether authorization was successful
messageStringError message
redirectUrlStringRedirect URL after authorization

Example:

javascript
export function sso(ctx) {
  console.log("ctx------>", informat.utils.toJSON(ctx));
  const query = ctx.query;
  const userName = query.userName;
  const password = query.password;
  //Find account by user name
  var accountList = informat.system.queryAccountList({
    filter: {
      conditionList: [{ fieldId: "userName", opt: "eq", value: query.userName }],
    },
  });
  console.log("accountList", accountList);
  if (accountList.size() == 0) {
    return {
      success: false,
      message: "Account does not exist",
    };
  }
  //Here we use Informat account password authentication, in practice you can use your own business logic for authentication
  var result = informat.system.validateAccount(userName, password);
  if (!result) {
    return {
      success: false,
      message: "Incorrect account or password",
    };
  }
  return {
    accountId: accountList[0].id,
    success: true,
    redirectUrl: "/workbench/app",
  };
}

Logout Interception and Redirect to Third-Party Page

  • When logging out from Informat, it will request the Informat logout address: https://next.informat.cn/account/main/logout
  • The system.systemHookLogoutFunc script intercepts the logout and returns to the third-party page
  • Redirect to the third-party page

In a newly created or existing application, find Application Design -> Scripts, and create a systemhook.js file (the script name can be customized). Implement the logout method in the systemhook.js file to handle business logic after logout.

javascript
export function logout(ctx) {
  console.log("ctx parameters:", ctx);
  return {
    success: true,
    redirectUrl: "/auth/login",
  };
}
  • Logout function input parameter ctx
PropertyTypeDescription
accountIdStringAccount ID
accountNameStringAccount name
tokenTypeStringToken type, index: PC web page; mobile: mobile terminal
requestObjectWebRequest object

WebRequest

Web request

ts
interface WebRequest {
  cookies: Object; //http cookies
  query: Object; //query parameters
  body: string; //http request body
  url: string; //http request url
  path: string; //path
  method: string; //request method
  ip: string; //ip address
}
  • Logout function return value
PropertyTypeDescription
successBooleanWhether logout was successful
messageStringError message
redirectUrlStringRedirect URL after logout

Example:

javascript
export function logout(ctx) {
  console.log("ctx------>", informat.utils.toJSON(ctx));
  return {
    success: true,
    redirectUrl: "/auth/login",
  };
}