# SSO Service

## What is SSO?

Single sign-on (SSO) is an authentication process that allows a user to access multiple applications with one set of login credentials.

![what_sso](./image/sso/what_sso.png)

## Which Types of SSO We Support?

The user authentication center platform/application is where we store user information like email, staff ID, password and so on.
The SSO protocol acts like a bridge that safely and easily guides us to the user authentication center.

![SSO-protocol](./image/sso/SSO-protocol.png)

### The Supported SSO Protocols

- SAML
- OIDC (OAuth 2.0)
- Restful (insureMO Standard)


### The Supported Platforms and Applications

- OKTA
- Microsoft Entra ID
- ADFS
- AUTH0
- Cognito
- Keycloak
- GIMO Member
- Customer User Applications…

## Basic UI Operations

### Entrance

 
- Click **Sign in** to log in to [insureMO Portal](https://portal.insuremo.com/) with your personal account.

    <div class="docs-info"><span class="docs-admonitions-text">info</span>

    If you do not have a personal insureMO account, click **Sign up** to register one.

    </div>
 

- At the top of the home page, click **Catalog**.
- On the Catalog page, in the left pane under **Utility & AI**, click **IAM**. You will find the **SSO Config** card. Click it and you will see the **API Details** and **Setting**.

![sso-card](./image/sso/sso-card.png)

- For creation and other actions, you need to click **Setting** to go to the **SSO Config** page.

![sso-setting](./image/sso/sso-setting.png)

- This will navigate to the main SSO configuration settings page where you can see the introduction of SSO and manage the service.

![sso-page](./image/sso/sso-page.png)

## How to Config SSO

- Click **How to config SSO**, you can select the environment and fill in your information in the upper panel and click **Generate**. 

![how-config_01](./image/sso/how-config_01.png)

- You'll see the SSO configuration method that works for you below.

![how-config_02](./image/sso/how-config_02.png)

<div class="docs-note"><span class="docs-admonitions-text">note</span>

After configuring the IDP side, please provide the App Federation Metadata URL to the insureMO side for configuration.  

insureMO tenant admin please go to **SSO card-> SSO config** to complete the configuration on the Service Provider side.

</div>

## SSO Configuration

### Create

- Click **Create SSO Config** on the SSO configuration console.

![config-create_01](./image/sso/config-create_01.png)

- Fill in the basic config information and click **Next**.

![config-create_02](./image/sso/config-create_02.png)

- In the config details, a config template will be generated for you. Replace the content with your relevant information, and click **Submit** to complete the creation.

![config-create_03](./image/sso/config-create_03.png)

<div class="docs-note"><span class="docs-admonitions-text">note</span>

**Client ID rules (Step 1):**

- Length MUST be less than 20 characters.
- Must not be one of the reserved names: `mo`, `platform`, `key`, `member`, `limo`.
- Must be unique within the tenant.
- The value you type here must equal the `insuremo_client_id` inside the Step 2 JSON, otherwise submission fails.

**Config details JSON rules (Step 2):**

- The JSON must have exactly ONE root key equal to the protocol selected in Step 1, for example `{"oidc": {...}}`.
- Fill real secrets (client secret, keys) directly in the editor. Never send them to anyone else.

</div>

### Configuration Field Reference

The config details of Step 2 are a JSON object whose root key is the auth type. The tables below explain the fields of each auth type.

#### oidc

| Field | Required | Description |
|-------|----------|-------------|
| `client_id` | Yes | App (client) ID issued by your identity provider application |
| `client_secret` | Yes | Secret of that application; fill the real value in the editor only |
| `host` | Yes | Base URL of the identity provider, e.g. `https://my-tenant.auth0.com` |
| `authorization_api` / `token_api` / `userinfo_api` | Yes | Standard OIDC endpoints, usually `{host}/authorize`, `{host}/oauth/token`, `{host}/userinfo`; verify them against the IdP's `/.well-known/openid-configuration` |
| `username_param` | Yes | The claim or profile path that carries the login name, e.g. `email`, `sub`, or `user_metadata.profile.auth0_user_id` |
| `redirect_uri` | Yes | Landing domains of your insureMO environments, comma-separated, e.g. `https://portal.insuremo.com,https://ptdev.insuremo.com` |
| `scope` | Optional | Default `openid email profile` |
| `sync_user_api` | Optional | Sync the logged-in user to the platform or an application after SSO login; see the Edit section for the values |

#### saml

| Field | Required | Description |
|-------|----------|-------------|
| `idp_metadata_url` | Yes (or paste XML) | Federation metadata URL of the identity provider |
| IdP metadata XML | Yes when there is no URL | Paste the metadata XML file into the **IdP metadata** XML editor of the create drawer; SAML creation is blocked when both URL and XML are empty |
| `signature_method` | Optional | Signature algorithm; default `http://www.w3.org/2001/04/xmldsig-more#rsa-sha256` |
| `username_param_name` | Yes | The SAML claim that carries the login name, e.g. `http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress` (email claim), the UPN claim, or NameID |
| `name_id_format` | Optional | Default `urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified` |
| `redirect_uri` | Yes | Landing domains of your insureMO environments, comma-separated |

#### cognito

| Field | Required | Description |
|-------|----------|-------------|
| `client_id` | Yes | App client ID of the AWS Cognito user pool |
| `user_pool_id` | Yes | User pool ID, format `{region}_{poolId}` |
| `region` | Yes | AWS region of the user pool |

Optional fields for admin operations exist in the page template; keep them only if you use them.

#### ldap

| Field | Required | Description |
|-------|----------|-------------|
| `ldap_server` | Yes | LDAP server address; use the `ldaps://` prefix to enable TLS, e.g. `ldaps://host:636` |
| `ldap_server_backups` | Optional | Backup servers, comma-separated; at most 2 |
| `ldap_base_dn` | Yes | Base DN used to search for users |

#### rest

| Field | Required | Description |
|-------|----------|-------------|
| `auth_url` | Yes | Sign-in API of your user service; the API contract is defined in the SSO Developer Guide below |
| `business_tenant_code` | Yes | Business tenant code agreed with insureMO |

Optional API fields (`notify`, `check`, `set_password`, `unlock`) can be configured when your user service provides them.

#### validate_token

| Field | Required | Description |
|-------|----------|-------------|
| `jwt_verification_key` | Yes | The PUBLIC key of the token issuer, in PEM format. Never configure a private key |

### Security Config and Allowed Landing URLs

After an SSO configuration is created, open **Edit → Security Config** to manage the sign-in security settings of that client, including the allowed landing URLs.

- **Allowed Landing URLs** (`domain_white_list`): a comma-separated list of domains where users may land after SSO login, e.g. `https://my-company.example.com`. For SAML and OIDC configurations, if this list is empty, login can still succeed but the browser will not navigate to your page — add your landing domains here after creation.
- Do not confuse the two URL types:
  - **Redirect URI / Reply URL** — the technical callback registered on the identity provider side. Use **How to config SSO** on the page to generate the exact values for your environment.
  - **Allowed Landing URLs** — where users are allowed to land after login, controlled on the insureMO side.
- Other Security Config settings include the account lock policy, token expiry time, and the two-factor authentication toggle.

### Edit

- Click **Edit** next to a particular record to edit the configuration.

![config-edit](./image/sso/config-edit.png)

* Config the sync_user_api:

after user login via sso, if you want to sync the user to our platform urp or GIMO app urp, you can set the sync user api like this:

1. Container platform urp :http://urp-v2-service.mo-fo/urpv2/account/sso/sync
2. GIMO APP urp :http://urp.platform/public/users/v1/sso/sync?role_policy=set_default_role

For Example：
```
{
  "oidc": {
    "client_id": "xARRposAjmPEV0TGAbAWvSKzJj0QwVvl",
    "client_secret": "5d1-EMH************LAD4p27",
    "authorization_api": "https://dev-wxexzn1gvkpz4a1v.us.auth0.com/authorize",
    "sync_user_api": "http://urp-v2-service.mo-fo/urpv2/account/sso/sync",
    "host": "https://dev-wxexzn1gvkpz4a1v.us.auth0.com/",
    "username_param": "user_metadata.profile.auth0_user_id",
    "redirect_uri": "https://portal.insuremo.com,https://ptdev.insuremo.com",
    "userinfo_api": "https://dev-wxexzn1gvkpz4a1v.us.auth0.com/userinfo",
    "token_api": "https://dev-wxexzn1gvkpz4a1v.us.auth0.com/oauth/token",
    "scope": "openid email profile",
    "insuremo_client_id": "tttdfsa"
  }
}
```

### Delete

- Click **Delete** next to a particular record to delete the configuration.

![config-delete](./image/sso/config-delete.png)

### Test

- After the SSO configuration is created successfully, you can verify whether the current configuration is available through a test.

- Click **Test** next to a particular record to test the configuration.

![config-test_01](./image/sso/config-test_01.png)

- There are different test methods for different auth types:

  1. `okta_oauth2` (deprecated — use the generic `oidc` type for new OKTA integrations)  
  This will navigate to OKTA's login page. If the user logs in successfully, the configuration is available.  

  ![config-test_okta](./image/sso/config-test_okta.png)

  2. oidc  
  This will navigate to the corresponding identity provider's login page. If the user logs in successfully, the configuration is available.  

  3. cognito  
  insureMO allows you to verify whether the token information from cognito is valid.  
  - Fill in your token in the pop-up test panel and click **Test**.
  
  ![config-test_cognito_01](./image/sso/config-test_cognito_01.png)

  - In the pop-up **Online Test** page, the information required for the request to validate the token interface is generated based on the previous steps. After clicking the **Test**, if the token is valid, the user information corresponding to this token will be generated on the right.
  
  ![config-test_cognito_02](./image/sso/config-test_cognito_02.png)

  4. saml  
  This will navigate to the configured identity provider's login page (the example below shows Microsoft Entra ID). If the user logs in successfully, the configuration is available.  
  
  ![config-test_saml](./image/sso/config-test_saml.png)
  
  5. rest  
  This type is a standard for insureMO, allowing the CAS service to connect to different user sources for the username and password verification.
  - Fill in your personal information in the test panel that pops up and click **Test**.  
  
  ![config-test_rest_01](./image/sso/config-test_rest_01.png)

  - In the pop-up **Online Test** page, the information required for the request to get the token interface is generated based on the previous steps. After clicking the **Test**, the corresponding token information will be generated on the right.
  
  ![config-test_rest_02](./image/sso/config-test_rest_02.png)

### Troubleshooting

Common errors when submitting the configuration:

| Error | Cause | Fix |
|-------|-------|-----|
| `the client id and authtype in json is not the same as the input parameter` (499) | The JSON root key does not equal the protocol selected in Step 1, or the `insuremo_client_id` value does not equal the Client ID typed in Step 1 | Correct the JSON root key / `insuremo_client_id` and submit again |
| Client ID rejected | Length is 20 characters or more, or it is a reserved name (`mo`, `platform`, `key`, `member`, `limo`) | Choose a shorter, non-reserved Client ID and use the same value in BOTH Step 1 and the JSON |
| Client ID already exists | The same Client ID is already configured in this tenant | Use a different Client ID, or edit the existing record instead of creating a new one |

### SSO Developer Guide 

#### Case 1: Login via External user service (Rest)
1. The external user service need to provides API according to CAS requirements. CAS calls the external user service through the Restful API to verify the user password. The parameters that will be passed are as follows:

```
curl --location --request POST 'http://user-mgmt-service.insuremo/account/signin'
--header 'Content-Type: application/json'
--data-raw
'{"name":"xxxx","password":"132xxxxxxdv!","tenantCode":"insuremo"}'
```

The format of the data returned after calling the user service is as follows:

accountName，email,tenantCode are required
```json
{
"body":"Check password success",
"data":{
"accountName":"xxxx",
"email":"xxxx@insuremo.com",
"mobile":"＋123xxxx123",
"tenantCode":"insuremo",
"tenantLockTimes":0,
"loginStatus":"1",
"autoUnlockTime":1800,
"accountLockNotifyFlg":""
},
"returnCode":"RC-00001"
}
```
The error is as follows:

```json
{
"data": {
"accountName": "xxxx",
"email": "xxxx@insuremo.com",
"mobile": "+153xxxx092",
"tenantCode": "insuremo",
"tenantLockTimes": 0,
"loginStatus": "",
"autoUnlockTime": 1800,
"accountLockNotifyFlg": ""
},
"errors": "CheckPassword error,password not right",
"returnCode": "RC-00099"
}
```

2.  Configure in the SSO Card

if you have a new client,please go to **SSO Card->SSO Config** and config it,follow the web page guide.

- After the configuration is complete, directly use the interface to obtain the Token. The incoming client ID needs to be changed as follows:

  - It's a must to add parameter: `x-mo-client-id` with your own client ID (the example above uses `member`).

  - You can add any parameter in JSON format to `Extend_params`, and CAS will store it temporarily for you to facilitate the subsequent use.
```
curl --location --request POST
'https://portal.insuremo.com/cas/get-token' 
--header 'Content-Type: application/json' 
--header 'x-mo-client-id: member' 
--header 'Authorization: Bearer jqmUVqXlSla6Q4E-rhTZ0w' 
--data-raw '{
"username":"REP0003","password":"dfsxxxxxj43","tenant_code":"tsubaddw","extend_params":[{"name":"testkey","value":"testparam"}]}'
```

- Authenticate user to identity and obtain additional parameters through the following API:
```
curl --location --request POST 'https://portal.insuremo.com/cas/validate-token' 
--header 'Authorization: Bearer dfsadsafdesfds'
Response:
{
"user_name": "xxxx@insuremo.com",
"tenant_code": "gimo",
"status": "SUCCESS",
"accountExpireDate": "2028-01-31T00:00:00Z",
"extend_params": [
{
"name": "testkey",
"value": "testparam"
}
],
"email": "xxxx@insuremo.com"
}
```
#### Case 2: Customer Applications/UIs want to login via  SAML or OIDC Identity Providers 
The CAS service has integrated Microsoft Entra ID (AZURE AD), ADFS, OKTA, Cognito,Auth0 and other platforms through the SAML/OIDC protocol.  
With the help of cas service, the applications could easily integrate with all these IDPs, only need to call CAS by Restful APIs.

**SAML integration**

![40a63ee8158a1723bfa2271935b4902e](./image/cas/40a63ee8158a1723bfa2271935b4902e.png)

![img.png](./image/cas/InsureMO_SAML_Protocol.png)


**OIDC Intergration**

![img.png](./image/sso/oidc_intergration.png)


1. Config the SAML/OIDC IDP in SSO Card
   * Follow the guide before, and remember the auth type and client ID
2. Develop APIs to redirect cas and the callback APIs after user login (SAML&OIDC the same process)
   1. one API in step 2 redirect to cas
       * OIDC API: `https://portal.insuremo.com/cas/sso/auth?tenant_code=mytenantcode&auth_type=oidc&client_id=mytenantcode&redirect_uri=https://myuiapi/gettokenbyexchangecode`
       * SAML API: `https://portal.insuremo.com/cas/sso/auth?tenant_code=mytenantcode&auth_type=saml&client_id=mytenantcode&redirect_uri=https://myuiapi/gettokenbyexchangecode`
   2. one API in step 13 to get token via exchange code
       * The integrator needs to use this exchange code to call CAS in the background to obtain the real user information and token.
       * Please refer to the following API about consume exchange code.

| Name         | Desc                                                                                                | Example                                      |
|--------------|-----------------------------------------------------------------------------------------------------|----------------------------------------------|
| tenant_code  | TenantCode agreed by both parties                                                                   | testtenant3809                               |
| redirect_uri | The URL received by the project party. They get the request and receive the exchange_code parameter | <https://portal.insuremo.com/cas/saml/hello> |
| auth_type    | saml,oidc                                                                                           | saml                                         |
| client_id    | If a tenant has multiple ADFS, use client_id to distinguish them                                    | clientid1                                    |

##### SAML login initiated from IDP. The whole process is as follows:

![cd63917bdf28e59bbb09b535c532e1e2](./image/cas/cd63917bdf28e59bbb09b535c532e1e2.png)

There are two supported ways for an IDP-initiated login, depending on what the IDP sends together with the SAML Response to the insureMO Assertion Consumer Service (`/cas/saml/acs`):

**Way 1 — Browser redirect (RelayState = `insuremo_<tenant_code>`).** Configure the IDP application to send the Relay State `insuremo_<tenant_code>` (for example `insuremo_mo-fo` for the `mo-fo` tenant; this is the same Relay State value described in the SP configuration sections). After the user authenticates, insureMO validates the assertion, issues the token, and redirects the browser (HTTP 302) to **the `redirect_uri` configured in the tenant's SAML configuration**, appending a one-time `exchange_code` query parameter (the landing page exchanges it for the real token). Notes:

- The landing address is purely the tenant-level configuration value — an end user cannot choose a custom redirect at login time in this flow.
- Configure a **single URL** in `redirect_uri` for this flow: the whole configured value is used as the redirect target, so a comma-separated list would produce an invalid URL.
- (For comparison: when the login is initiated from insureMO itself — SP-initiated — the browser returns to the page that started the login, and a caller-supplied redirect must pass the `redirect_uri` whitelist check.)

**Way 2 — API style (no RelayState; `tenant_code` in the form data).** The integrator (usually the front end) posts the SAML Response directly to insureMO and reads the token from the JSON response; no browser redirect happens. Steps:

######  1: Customer login.

Select the current site on the customer's ADFS page. 

![11fd4921398349d8858b40a8cb21834d](./image/cas/11fd4921398349d8858b40a8cb21834d.png)

######  2: The login interface of the current client's IDP configuration is provided by the integrator, as follows:

curl --location --request POST 'https://myloginpage/saml/acs'\\

form `SAMLResponse="PHNhbWxwOlJlc3BvbnNlIElEPSYXNpcz....0aW9uPjwvc2FtbHA6UmVzcG9uc2U+`
######  3: After receiving the login request from IDP, the integrator (usually the front end) calls the following interface of Container and sends SAMLResponse and tenant_code through formdata.
```
curl --location --request POST 'https://dev.insuremo.com/cas/saml/acs'

--form 'SAMLResponse="PHNhbWxwOlJlc3BvbnNlIElEPSYXNpcz....0aW9uPjwvc2FtbHA6UmVzcG9uc2U+"'

--form 'tenant_code="testchen3809"' 
```
Container returns the token of the current user, where there is no username. When required by the integrator, the username needs to be replaced with the token.
```
Response：
{
    "access_token": "bbmkLEg7TmmeKuMgDv5Q_A",
    "exchange_code": "5b04c5f9f1a34f67bb4c20fa8cd7d90e",
    "expire_in": 7216,
    "message": "",
    "retry_times": 0
}
```
The interfaces for exchanging Token for user information are as follows:
```
curl --location --request POST 'https://portal.insuremo.com/cas/validate-token' 
--header 'Authorization: Bearer JbiSwyWaSNWUEI85eTmH0w'
Response：
{
    "user_name": "xxxx",
    "tenant_code": "insuremo",
    "status": "SUCCESS"
}
```

#### Customer configures ADFS/AZURE AD

##### To configure the ADFS server, follow the following process:

###### *A*. Configure Relying party trusts.

Import the Metadata file on the SP side provided by InsureMo, the address is: `<https://dev.insuremo.com/cas/saml/metadata>`. Download it directly with the browser, or configure the URL directly. Each environment is different, adjust `<https://dev.insuremo.com>` according to the actual domain address.

Import metadata file for application

![6b48b3f1d40cf3650f5f5bdf21cd4a19](./image/cas/6b48b3f1d40cf3650f5f5bdf21cd4a19.png)

Finish it in the next step

###### B. Configure claim rule

Right-click on the trusts to edit rule

![81e976f1926aef3bccae9a679b09e35e](./image/cas/81e976f1926aef3bccae9a679b09e35e.png)

Add send claim rule

![554bc00078d44de92ae9208cb319c1f7](./image/cas/554bc00078d44de92ae9208cb319c1f7.png)

![25b06d32a3f6549f068a24fba0cf9824](./image/cas/25b06d32a3f6549f068a24fba0cf9824.png)

Add incoming rule

![f8ac86254ac5af4a1c4a29c2d5d5015e](./image/cas/f8ac86254ac5af4a1c4a29c2d5d5015e.png)

![fd80035b726b2e7a7c25881f93418456](./image/cas/fd80035b726b2e7a7c25881f93418456.png)

###### C. Export the ADFS metadata file

This metadata is the ADFS IDP metadata.

##### Follow the following process to configure the AZURE AD

How to Config the SAML SSO in AZURE AD

###### Add a new application:

![ccfd7f6932b47dcd58c23e4d8f7aa745](./image/cas/ccfd7f6932b47dcd58c23e4d8f7aa745.png)

![0374c63620db79d619aadc899c4eb758](./image/cas/0374c63620db79d619aadc899c4eb758.png)

###### Set up the single sign on for the application

![009758843ca5a01662eb166e4a7eea39](./image/cas/009758843ca5a01662eb166e4a7eea39.png)

The identifier id (Entity ID) should
be: `<https://sandbox.sg.insuremo.com/cas/saml/metadata>`

Reply URL should be: `<https://sandbox.sg.insuremo.com/cas/saml/acs>`

Relay State should be: valpas

<div class="docs-note"><span class="docs-admonitions-text">note</span>

The URLs and the Relay State above are examples from a sandbox environment. Replace the domain with your own insureMO environment domain and use your own values.

</div>

After config, please provide the Federation Metadata XML to the insureMO team to complete the configuration.

![b5d0afd422f504f4e261f8c0eb21384a](./image/cas/b5d0afd422f504f4e261f8c0eb21384a.png)

![69956748af46fbc2bd8b84fc3088d2ee](./image/cas/69956748af46fbc2bd8b84fc3088d2ee.png)

###### C.give the metadata file URL to insureMO team,  insureMO team do the SSO Configuration in SSO Configuration card 



#### Test

##### AZURE AD Test the sso

1. IDP int test

![b18f51cc2e21fcb206dab2e7b905e0db](./image/cas/b18f51cc2e21fcb206dab2e7b905e0db.png)

1. Sp init test, go to
   page: `<https://sandbox-s-auth.insuremo.com/cas/login?client_id=key&response_type=code&redirect_uri=https://sandbox.sg.insuremo.com/>`
   ,input the tenant code valpas,  click **AZURE AD**

    1. The `redirect_url` should be change to your homepage.

####  Post-maintenance of SAML

##### Change the default public key and private key: (Please arrange a suitable time,for SSO will be interrupted during this process)

If the public and private keys need to be replaced next time, the steps are as follows, and it is recommended to supplement the subsequent documentation on the project to prevent trouble caused by personnel replacement.

1. Generate RSA private key file

![f2a7488c35d50103bafcd81f938af5cc](./image/cas/f2a7488c35d50103bafcd81f938af5cc.png)

2. Use the private key to generate a certificate, and specify the period here, then you can see the content of the public key when you open the certificate.

![ff1830ac37f7f09045398329ff259118](./image/cas/ff1830ac37f7f09045398329ff259118.png)

3. Assign the private key and public key content to the configuration center

![6dfd31d497aaf41a12d873b3bcc74ae2](./image/cas/6dfd31d497aaf41a12d873b3bcc74ae2.jpg)

4. Restart CAS to get new metadata (the metadata contains public key information)

5. After modifying the metadata according to the requirements of the project team, provide it to the customer.


<div class="docs-note"><span class="docs-admonitions-text">note</span>

Links to external websites and third-party features contained in this document are for demonstration purposes only. Such links and features do not constitute our endorsement or recommendation. We neither control nor assume responsibility for the content, services, or privacy practices of these third parties. Users are advised to independently review the respective terms and privacy policies.

</div>

# FAQ
* Q: If I want to let the user login insureMO via my user service, how could I connect to the CAS service ?
* A: External user services that support Restful interfaces can be added to CAS,please go to External user service provides API according to CAS requirements.