Bookandlink Documentations

API Single Sign On > Single Sign On

Single Sign On

EnvironmentBASE_URLAPI_BASE_URL
Staginghttps://sso.bnlstg.comhttps://sso-api.bnlstg.com/api
Production
SSO Authentication Flow

How todo integration

To be able to integrate a website with SSO, we must register your web application in SSO. Later your web application will be called an SSO client product. To become an SSO client, we need this following information.

#InfoDescription
 1Client NameIndicates the name of the client website that will appear on the SSO dashboard
 2Base URLIndicates the main page URL of the client. For this example : https://pos.domain.com. This URL will be used as the redirect destination address if the login is successful in SSO. SSO will automatically add the path & query parameter sso/callback?token=xxx to the destination URL.
 3DescriptionIndicate short description about that web client
 4Logo URLIn the form of a logo URL from the website.
 5API Base URL

In the form of an API URL from the client, this URL will later be used by SSO to communicate regarding sending, updating or deleting user data. Example value : https://pos.domain.com/sso/callback. SSO will automatically add the path to that URL.
This is the entire list of endpoints you should prepare for integration with SSO

  • [POST] https://pos.domain.com/sso/callback/check_user
  • [POST] https://pos.domain.com/sso/callback/check_email
  • [POST] https://pos.domain.com/sso/callback/assign_user
  • [POST] https://pos.domain.com/sso/callback/update_user
  • [POST] https://pos.domain.com/sso/callback/remove_user
  • [GET] https://pos.domain.com/sso/callback/get_property/{external_id}
  • [GET] https://pos.domain.com/sso/callback/get_roles
  • After being registered with SSO, the client will get a Product Token. It will be used as an authentication method during the data transfer process. The product token will be static and consists of random characters in string form.

    Example : lVC3WbusmJFK4UClg3wlJFOp4A6bxSxj1S2ezUqkSNIg8347fkOiovkAlGnfc.

    Note:

    If you don't want to use the default path generated by SSO for data communication, you can customize the URL. Below is a list of URLs and actions that you can customize based on your product.

    Action NameMethodDescription
    verifyGETRedirect destination after login success.
    This URL will automatically added URL parameter token by SSO.
    check userPOSTCalled when user not found in SSO on login process. Used on Check_User method
    check by emailPOSTThis will be called when a user resets their password in SSO but the user data has not been previously synchronized. Used on Check by email method.
    assign_userPOSTCalled when user assign product to their sub user. Used on Assigning User in Product
    get_propertyGETPart of assign user process. It will called on Get Property
    get_rolesGETPart of assign user process. It will called on Get Roles
    remove_userPOSTCalled on user remove product access to their sub user. It will called on Un Assign User process

    When accessing product custom endpoint, SSO will send Product Token as an authorization header.

    API Responses

    Each response provided by SSO will have the following json format. Apart from the following JSON format, you can also check the state of the process you are carrying out via the http response code which is responded to by SSO.

    Success Response
    {
      "status": "success",
      "message": "This is success message",
      "data": ""
    }
    Fail Response
    {
      "status": "error",
      "message": "Unable to proccess",
      "data": ""
    }
    FieldDescriptionstype
    StatusIndicates whether the process was successful or failed, the value of this field can be success if the process is successful and error if it failsbool
    MessageProvide a message or brief description of the process carried out on the SSOtext
    DataThis field can be anything depending on the endpoint used. Each endpoint has a different responseany

    Client Login

    Before integration with SSO, the client may be have had its own login page which was accessed if the user had not logged in to the website. If you have integrated with SSO, you can redirect to the BASE_URL of SSO to carry out the user login process.

    When redirected to that page, you also have to enter a query parameters in the URL.

    • redirect, Contains the URL that SSO will redirect to when the login process is successful. By default, if you do not include this parameter, a redirect will be made to the SSO dashboard. For example : https://pos.domain.com

    The final URL will look link this:

    https://sso.bnlstg.com?redirect=https://pos.domain.com

    SSO Login Callback

    After successful login on the SSO page, the user will be directed to the URL you provided in the section above by reading the user token. This user token is a key that will later be used to verify the user. This token will be sent to the SSO Client via the parameters in the callback URL. SSO will automatically add the path "sso/callback" to the redirect URL you used previously.

    Example : https://pos.domain.com/sso/callback?token=sj9293uruwejdwe923jfee

    On this path, the next task is for the client to process the token. The client must carry out a verification process to ensure that the token is valid. The verification process can be done using the endpoint API_BASE_URL/user/verify-by-product .

    GET : API_BASE_URL/user/verify-by-product

    curl --location 'API_BASE_URL/user/verify-by-product' 
    \ --header 'Authorization: Bearer sj9293uruwejdwe923jfee..' 
    \ --header 'ProductAuthorization: Bearer lVC3WbusmJFK4UClg3wlJFOp4A6bxSxj1S2ezUqkSNIg8347fkOiovkAlGnfc'
    Header Parameter
    FieldDescriptionstype
    AuthorizationBearer + user_tokentext
    ProductAuthorizationBearer + product_tokentext
    Response Parameters
    {
      "status": "success",
      "message": "Logged in user",
      "data": {
        "user": {
          "id": 2,
          "username": "johndoe",
          "email": "user@domain.com",
          "first_name": "John",
          "last_name": "Doe",
          "phone": "",
          "phone_verified": false,
          "email_verified": false,
          "status": true,
          "mfa_active": true,
          "remember_token": "",
          "last_login": "2024-01-10T02:04:14.692Z",
          "last_login_ip": "127.0.0.1",
          "created_at": "2023-11-21T09:03:28.119Z",
          "updated_at": "2024-01-10T02:04:14.693Z",
          "main_user_id": null
        },
        "user_product": {
          "user_id": 2,
          "product_id": 1,
          "external_id": "16",
          "role": "admin",
          "product": {
            "id": 1,
            "name": "Point Of Sales",
            "url": "https://pos.domain.com",
            "description": "",
            "status": true,
            "image_url": "https://pos.domain.com/assets/logo.png",
            "ip": "",
            "token": "zIXOfxkiuFQny966eAU1mT4abkaWcz8v3v8psN88",
            "api_endpoint": "https://pos.domain.com/sso/callback",
            "created_at": "2023-11-03T15:40:42.419Z",
            "updated_at": "2023-11-03T15:40:42.419Z"
          }
        }
      }
    }
    FieldDescriptionstype
    userRepresent the user that successfully verified by user_tokenobject
    user.idUser ID, uniquely identifying the user.integer
    user.usernameRepresent the username in SSOstring
    user.emailThe user email to used to login in SSOstring
    user.first_nameFirst name of the user.string
    user.last_nameLast name of the user.string
    user.phoneUser's phone number (if provided).string
    user.phone_verifiedIndicates whether the user's phone number has been verified.boolean
    user.email_verifiedIndicates whether the user's email address has been verified.boolean
    user.statusUser account status. true represents an active account.boolean
    user.mfa_activeIndicates whether Multi-Factor Authentication (MFA) is active for the user.boolean
    user.remember_tokenToken used for remembering the user across sessions.string
    user.last_loginDate and time of the user's last login.datetime
    user.last_login_ipIP address from which the user last logged in.string
    user.created_atDate and time when the user account was created.datetime
    user.updated_atDate and time when the user account was last updated.datetime
    user.main_user_idID of the main user if applicable.integer
    user_productRepresent user mapping with the client productobject
    user_product.user_idUser ID, uniquely identifying the user.integer
    user_product.product_idThe product ID that has ben registered in SSO. This field represent your client product id in SSO storage data.integer
    user_product.external_idThis column will store the user ID of your user in the client application.
    This column is the main key that can be used to verify the user in your application. For example, you can retrieve user data based on external_id, then if the user data is in your local database, then you can save the user data in a session which indicates the login process has been successful.
    string
    user_product.roleUser role in client applicationstring
    Error Responses
    CodeMessageDescription
    401Please login to continueIndicate the user token is expired
    404User not found, please sign inIndicate the user was not found or deactivate in SSO
    401UnauthorizedIndicate the product token is un valid
    404User not found by product tokenIndicate the user was not assign to current client Product

    Check User

    If you don't import all user data, you can use this endpoint as an alternative. In this process, SSO will POST user credentials in the form of email and password to your API product.

    The product must handle searching for user data based on email and password then returning it so that it can be processed by SSO. This process will be called if the user is not found on the SSO page during the login process.

    POST : https://pos.domain.com/sso/callback/check_user

    Body Parameter
    FieldDescriptionstype
    emailUser input emailstring
    passwordUser input passwordstring

    Expected API Responses
    {
      "status": "success",
      "message": "User founded",
      "data": {
        "external_id": "1",
        "main_user_external_id" : "0",
        "username": "johndoe",
        "email": "user@domain.com",
        "first_name": "John",
        "last_name": "Doe",
        "status": 1,
        "role" : "staff",
        "phone": "",
        "phone_verified": 0,
        "email_verified": 1,
        "mfa_active": 1
      }
    }
    FieldDescriptionstype
    external_idAn external identifier associated with the user, used for integration purposes.string
    first_nameThe first name of the user.string
    last_nameThe last name or surname of the user.string
    main_user_external_idAn external identifier referring to the main user associated with this account (if applicable).string
    phoneThe phone number associated with the user account.string
    statusA numerical value representing the status of the user account (e.g., 1 for active, 0 for inactive).boolean
    usernameThe unique username associated with the user account.string
    roleUser role in your applicationstring
    mfa_activeRepresent the status of multi factor authenticationboolean
    email_verifiedIndicates whether the user's email address has been verified.boolean
    phone_verifiedIndicates whether the user's phone number has been verified.boolean

    Check User by Email

    If the user has never synchronized with SSO, but its the first time they access SSO, and wants to reset the password. SSO will use this endpoint to synchronize from product. If a user is found on the product, we will save the user data and continue by sending a password reset email.

    The product must handle searching for user data based on email then returning it so that it can be processed by SSO.

    POST : https://pos.domain.com/sso/callback/check_email

    Body Parameter
    FieldDescriptionstype
    emailUser input emailstring

    Expected API Responses
    {
      "status": "success",
      "message": "User founded",
      "data": {
        "external_id": "1",
        "main_user_external_id" : "0",
        "username": "johndoe",
        "email": "user@domain.com",
        "first_name": "John",
        "last_name": "Doe",
        "status": 1,
        "role" : "staff",
        "phone": "",
        "phone_verified": 0,
        "email_verified": 1,
        "mfa_active": 1
      }
    }
    FieldDescriptionstype
    external_idAn external identifier associated with the user, used for integration purposes.string
    first_nameThe first name of the user.string
    last_nameThe last name or surname of the user.string
    main_user_external_idAn external identifier referring to the main user associated with this account (if applicable).string
    phoneThe phone number associated with the user account.string
    statusA numerical value representing the status of the user account (e.g., 1 for active, 0 for inactive).boolean
    usernameThe unique username associated with the user account.string
    roleUser role in your applicationstring
    mfa_activeRepresent the status of multi factor authenticationboolean
    email_verifiedIndicates whether the user's email address has been verified.boolean
    phone_verifiedIndicates whether the user's phone number has been verified.boolean

    Assign User

    The register or assign user process is the process of registering users and integrating them with SSO. There are 2 integration options that will be carried out. First, create a user from SSO and then send it to the SSO Client to be registered. Second, clients register users from local applications and then send them to SSO for data integration.

    Assign User From SSO to Product

    On assigning a user, SSO will include the role and properties of the product or client to be assigned. Role and properties will become a select dropdown, so that each SSO client must provide an endpoint that is used by SSO to retrieve these options.

    The suffix of this endpoint has been determined by SSO, while the base URL of this API is the base URL registered when registering the client product in SSO. In this example, the API base URL used is https://pos.domain.com/sso/callback so the list of endpoints you must prepare is:

    Get Properties

    GET : https://pos.domain.com/sso/callback/get_property/{external_user_id}

    Path Variable
    FieldDescriptionstype
    external_user_idThis field will be filled by your product user id that has login to SSO and willing to assigning some sub user to your another producttext
    Expected API Responses

    Your endpoint must return JSON responses that will look like this.

    {
      "status": "success",
      "message": "Property option by user",
      "data": [
        {
          "id": 5,
          "label": "Colosseum PIZZA"
        }
      ]
    }
    Option Result

    SSO will creating select option based on your id as the value, and label as option label.

    Get Roles

    GET : https://pos.domain.com/sso/callback/get_roles

    Expected API Responses
    {
      "status": "success",
      "message": "Role list",
      "data": [
        {
          "value": "admin",
          "label": "Admin"
        },
        {
          "value": "sales",
          "label": "Sales"
        },
        {
          "value": "waiter",
          "label": "Waiter"
        },
        {
          "value": "kitchen",
          "label": "Kitchen"
        }
      ]
    }
    Option Result

    SSO will create a role select option based on the application you created.

    Assigning User in Product

    Once a user is successfully assigned to a product in SSO, SSO will send the user data via API to the SSO Client. In this process, the client must handle the user data to be stored in the user database. Once the user data is successfully saved, you must provide a response back to SSO, so that SSO will process the user data.

    POST : https://pos.domain.com/sso/callback/assign_user

    Body Parameter
    FieldDescriptionstype
    emailEmail of the userstring
    first_nameFirst name of the user.string
    last_nameLast name of the user.string
    main_user_idYour main user id (sso client external_id) who assigned the user to the product.string
    phoneUser's phone number (if provided).string
    property_idI will be in the form of an array, indicating that 1 user can be assigned to several propertiesarray
    roleRole of user based on your select optionstring
    usernameEmail of the userstring
    Expected API Responses
    {
      "status": "success",
      "message": "User successfully assigned",
      "data": "{user_id}"
    }
    FieldDescriptionstype
    statusmust be “success“ if the process is success, and “error“ is the register process is fail.string
    messageOptional messagestring
    dataThis is mandatory. Must be fill with your user ID that has ben registered. In SSO it will be stored as user external_idstring

    Assign User From Client Product to SSO

    This is a reverse scenario that registers users is on your product, then the product must send the user data to SSO to be integrated. SSO will return a successful or failed response according to the condition of the data you sent.

    POST : API_BASE_URL/user/product/add-user

    curl --location 'API_BASE_URL/user/product/add-user' \
    --header 'ProductAuthorization: Bearer lVC3WbusmJFK4UClg3wlJFOp4A6bxSxj1S2ezUqkSNIg8347fkOiovkAlGnfc' \
    --form 'username="johndoe"' \
    --form 'email="user@domain.com"' \
    --form 'first_name="John"' \
    --form 'last_name="Doe"' \
    --form 'password="supersecurepassword"' \
    --form 'status="1"' \
    --form 'phone=""' \
    --form 'phone_verified="1"' \
    --form 'email_verified="1"' \
    --form 'external_id="1000"' \
    --form 'main_user_external_id="1"' \
    --form 'role="kitchen"'
    FieldDescriptionstype
    emailThe email address of the user. This must be uniqueinteger
    email_verifiedA boolean value indicating whether the user's email address has been verified (1 for true, 0 for false).boolean
    external_idAn external identifier associated with the user, used for integration purposes.string
    first_nameThe first name of the user.string
    last_nameThe last name or surname of the user.string
    main_user_external_idAn external identifier referring to the main user associated with this account (if applicable).string
    passwordThe password for the user account. Ensure it is a secure and strong password.string
    phoneThe phone number associated with the user account.string
    phone_verifiedA boolean value indicating whether the user's phone number has been verified (1 for true, 0 for false).boolean
    roleThe role or designation assigned to the user (e.g., "kitchen"). Specifies the user's functional role within the system.string
    statusA numerical value representing the status of the user account (e.g., 1 for active, 0 for inactive).boolean
    usernameThe unique username associated with the user account.object
    Response Parameters
    {
        "status": "success",
        "message": "User saved successfully",
        "data": {
            "id": 2,
            "username": "johndoe",
            "email": "user@domain.com",
            "first_name": "John",
            "last_name": "Doe",
            "phone": "082xxxxxxx",
            "phone_verified": true,
            "email_verified": true,
            "status": true,
            "mfa_active": true,
            "meta_data": "",
            "remember_token": "",
            "last_login": null,
            "last_login_ip": "",
            "created_at": "2023-10-30T14:32:51.877Z",
            "updated_at": "2023-10-30T14:44:48.992+08:00",
            "main_user_id": null,
        }
    }
    Error Responses
    Status CodeMessageDescription
    400Username or Email is already exitsIndicate the user with username or email was already exists
    500Error occurredInternal Server Error
    400User with that ID was already registeredIndicate your external_id was already registerer

    Note: If this error was occurred, you can delete your user in your local database, or rollback you database transaction.

    Update User

    There are 2 scenarios for the user update process.

    1. First, updates are initiated by users through the SSO (Single Sign-On) dashboard. In this scenario, SSO will send the update results to the relevant product to reflect the changes made.
    2. Second, the scenario involves users updating their profiles directly from the product. The product must send these updates to the SSO for data integration.

    Update User from SSO to Product

    Once a user is successfully updated in SSO, SSO will send the user data via API to the SSO Client. In this process, the client must handle the user data to be update by external_id.

    POST : https://pos.domain.com/sso/callback/update_user

    Body Parameter
    FieldDescriptionstype
    emailEmail of the userstring
    first_nameFirst name of the user.string
    last_nameLast name of the user.string
    main_user_idYour main user id (sso client external_id) who assigned the user to the product.string
    phoneUser's phone number (if provided).string
    property_idI will be in the form of an array, indicating that 1 user can be assigned to several propertiesarray
    roleRole of user based on your select optionstring
    usernameEmail of the userstring
    avatarUser avatar imagestring
    Success API Responses
    {
      "status": "success",
      "message": "User updated successfully",
      "data": null
    }
    Error API Responses
    {
      "status": "error",
      "message": "Unable to update user",
      "data": null
    }

    Update User from Product to SSO

    This is a reverse scenario that user update their profile in product, then the product must send the user data to SSO to be integrated with SSO. SSO will return a successful or failed response according to the condition of the data you sent

    PUT : API_BASE_URL/user/{external_id}/product/update-user

    curl --location --request PUT 'API_BASE_URL/user/1/product/update-user' \
    --header 'ProductAuthorization: Bearer lVC3WbusmJFK4UClg3wlJFOp4A6bxSxj1S2ezUqkSNIg8347fkOiovkAlGnfc' \
    --form 'username="johndoe"' \
    --form 'email="user@domain.com"' \
    --form 'first_name="John"' \
    --form 'last_name="Doe"' \
    --form 'avatar="http//example.com/avatar-image.png"'
    Path Variables
    FieldDescriptionstype
    external_idYour local database user IDstring
    Body Parameter
    FieldDescriptionstype
    emailEmail of the userstring
    first_nameFirst name of the user.string
    last_nameLast name of the user.string
    phoneUser's phone number (if provided).string
    usernameUsername of the userstring
    avatarUser avatar imagestring | optional
    Response Parameters
    {
      "status": "success",
      "message": "User updated successfully",
      "data": {
        "id": 2,
        "username": "johndoe",
        "email": "user@domain.com",
        "first_name": "John",
        "last_name": "Doe",
        "avatar" : "http//example.com/avatar-image.png",
        "phone": "081xxxxxxxx",
        "phone_verified": true,
        "email_verified": true,
        "status": true,
        "mfa_active": true,
        "meta_data": "",
        "remember_token": "",
        "last_login": null,
        "last_login_ip": "",
        "created_at": "2023-10-30T14:32:51.877Z",
        "updated_at": "2023-10-30T14:44:48.992+08:00",
        "main_user_id": null
      }
    }
    Error Responses
    Status CodeMessageDescription
    400Username or Email is already exitsIndicate the user with username or email was already exists
    400Unable to get user dataUnable to get user data by external_id

    Note : If this error occurred, you can rollback the changes

    Un Assign User

    The user unassign process is carried out on the SSO dashboard for users on the product. For the unassign process, SSO will send unassigned user data from the related product. You can carry out a soft delete process or deactivate the user on your product.

    POST : https://pos.domain.com/sso/callback/remove_user

    Body Parameter
    FieldDescriptionstype
    user_idYour local database user ID for the deleted userstring
    Expected API Responses
    {
      "status": "success",
      "message": "User deleted successfully",
      "data": null
    }

    Import User

    This endpoint is used when you want to carry out the bulk data import process for users

    POST : API_BASE_URL/user/import

    curl --location 'API_BASE_URL/user/import' \
    --header 'ProductAuthorization: Bearer lVC3WbusmJFK4UClg3wlJFOp4A6bxSxj1S2ezUqkSNIg8347fkOiovkAlGnfc' \
    --header 'Content-Type: application/json' \
    --data-raw '[
        {
            "external_id": "1",
            "main_user_external_id" : "0",
            "username": "admin",
            "email": "admin@domain.com",
            "first_name": "admin",
            "last_name": "Admin User",
            "status": 1,
            "phone": null,
            "phone_verified": 0,
            "email_verified": 1
        },
        {
            "external_id": "28",
            "main_user_external_id" : "1",
            "username": "john",
            "email": "john.doe@domain.com",
            "first_name": "JOhn",
            "last_name": "Doe",
            "status": 1,
            "phone": null,
            "phone_verified": 0,
            "email_verified": 1
        }
    ]'
    Header Parameter
    FieldDescriptionstype
    ProductAuthorizationBearer + product_tokentext
    Body Parameter
    FieldDescriptionstype
    email_verifiedA boolean value indicating whether the user's email address has been verified (1 for true, 0 for false).boolean
    external_idAn external identifier associated with the user, used for integration purposes.string
    first_nameThe first name of the user.string
    last_nameThe last name or surname of the user.string
    main_user_external_idAn external identifier referring to the main user associated with this account (if applicable).string
    phoneThe phone number associated with the user account.string
    statusA numerical value representing the status of the user account (e.g., 1 for active, 0 for inactive).boolean
    usernameThe unique username associated with the user account.string
    Response Parameters
    {
        "status": "success",
        "message": "User data imported successfully",
        "data": {
            "imported": 0,
            "error_validation": 0,
            "unique_validation": 2,
            "total_error": 0,
            "total_data": 2
        }
    }
    FieldDescriptionstype
    importedThe number of user that successfully importedinteger
    error_validationThe number of user data that fail to import due to error form validationinteger
    unique_validationThe number of user data that fail to import due to error unique username or emailinteger
    total_errorThe number of internal SSO errorinteger
    total_dataTotal data that has been processedinteger
    • On importing user data process, the password will be set empty in the Single Sign-On (SSO), so when attempting to log in to SSO, users will need to go through the password reset process first before being able to proceed with the login process.

    Get Product List

    This endpoint is used to get a list of products based on logged in users. On this endpoint, you can display a list of products in your user dashboard. This is useful so that users can easily navigate to each product without remembering the product URL.

    Note: This endpoint will only return a list of products other than the product you used in the Auth Product Token in the header parameters.

    GET : API_BASE_URL/product/list/by-user-product

    curl --location 'API_BASE_URL/product/list/by-user-product' \
    --header 'Authorization: Bearer sj9293uruwejdwe923jfee..' \
    --header 'ProductAuthorization: Bearer lVC3WbusmJFK4UClg3wlJFOp4A6bxSxj1S2ezUqkSNIg8347fkOiovkAlGnfc...'
    Header Parameter
    FieldDescriptionstype
    AuthorizationBearer + user_tokentext
    ProductAuthorizationBearer + product_tokentext
    Response Parameters
    {
        "status": "success",
        "message": "Product list by user product",
        "data": [
            {
                "id": "2",
                "name": "Channel Manager",
                "url": "https://cm.domain.com",
                "description": "Some product description",
                "status": true,
                "image_url": "https://cm.domain.com/assets/logo.png",
                "external_id": "272"
            }
        ]
    }
    FieldDescriptionstype
    idSSO Product IDstring
    nameProduct Namestring
    urlClient product URLstring
    statusIndicate user product status in SSOboolean
    image_urlProduct logo imagestring
    external_idLogged in user external_idstring
    Error Responses
    Status CodeMessageDescription
    401Please login to continueIndicate the user token is expired
    401User not found, please sign inIndicate the user was not found or deactivate in SSO
    401UnauthorizedIndicate the product token is un valid

    Logout User

    During the logout process, SSO marks the user's token as expired. To carry out this process, you can direct your user to the BASE_URL + /auth/logout page.

    GET : BASE_URL/auth/logout

    Next, SSO will carry out the logout process and end by redirecting your user to the SSO login page.

    On this page