Single Sign on pre

The FIB Single Sign-On (SSO) service simplifies and streamlines the login process for your business, enabling seamless authentication through FIB.

WARNING

This feature is experimental, and is not available in the latest version yet. Please install the SDK with pretag instead:

npm
yarn
pnpm
bun
deno
npm install @first-iraqi-bank/sdk@pre

Usage

You can import the SDK classes and types from the sso entrypoint:

import { SingleSignOnSDK } from "@first-iraqi-bank/sdk/sso"

The SingleSignOnSDK class has a static method that gives you an instance of the SDK configured with your API credentials:

fib-sso.js
import { SingleSignOnSDK } from "@first-iraqi-bank/sdk/sso"

const clientId = process.env.FIB_SSO_CLIENT_ID
const clientSecret = process.env.FIB_SSO_CLIENT_SECRET
const environment = process.env.FIB_ENV // 'dev', 'stage', or 'prod'

export const FIBSingleSignOn = SingleSignOnSDK.getClient(clientId, clientSecret, environment)

Now you can import FIBSingleSignOn from anywhere in your project and call its methods to initiate SSO and check the status of the SSO request.

TIP

Checkout FIB Single Sign On documentations for more info and how to obtain your credentials

  • initiate(signal?: AbortSignal): Initiates SSO process and returns SSO details including ssoAuthorizationCode.
  • getUserDetails(paymentInput: PaymentInput, accessToken: string, signal?: AbortSignal): Gets details of the user linked with the ssoAuthorizationCode.

initiate

This method sends a request to the First Iraqi Bank's identity server, initiating the SSO process and returning the necessary details including the ssoAuthorizationCode.

import { FIBSingleSignOn } from "./fib-sso.js"
const res = await FIBSingleSignOn.initiate()
const { ssoAuthorizationCode, expiresIn } = await res.json()

The ssoAuthorizationCode is crucial for the next step, as it allows you to retrieve user details associated with the SSO request.

getUserDetails

This method retrieves the user details associated with the provided ssoAuthorizationCode in JSON format.

You don't need to manually type the returned JSON as it is already typed in the SDK.

import { FIBSingleSignOn } from "./fib-sso.js"
const ssoAuthorization = "your_sso_authorization_code_here"
const res = await FIBSingleSignOn.getUserDetails(ssoAuthorization)
const userDetails = await res.json()