For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

MOSIP Registration Integration

This section assumes that you are already familiar with the general registration integration concepts. If you have not read that page, read it first for a high-level introduction to the concepts, and then return here.

Architecture

From OpenCRVS v2.0.0, MOSIP registration integration is implemented through action confirmation handlers registered in the country configuration server. When a registrar performs a REGISTER action, OpenCRVS core calls the country configuration's registered action trigger. Learn more about action triggers. The trigger can respond synchronously (HTTP 200) or defer the response for asynchronous external validation (HTTP 202).

The reference implementation is the testland country configuration in the OpenCRVS Core repository.

Route registration

Routes for MOSIP integration are registered in src/index.ts:

server.route({
  method: 'POST',
  path: `/trigger/events/${Event.Birth}/actions/${ActionType.REGISTER}`,
  handler: onMosipBirthRegisterHandler
})

server.route({
  method: 'POST',
  path: `/trigger/events/${Event.Death}/actions/${ActionType.REGISTER}`,
  handler: onMosipDeathRegisterHandler
})

Birth registration handler

The onMosipBirthRegisterHandler is defined in src/api/registration/index.ts.

The handler:

  1. Extracts the declaration data from the event.

  2. Generates a registration number.

  3. Evaluates eligibility via shouldForwardBirthRegistrationToMosip.

  4. If eligible, creates a createMosipInteropClient and calls mosipInteropClient.register(...) with the child's biographic data.

  5. Returns HTTP 202 (deferred) to place the record in the "Awaiting external validation" work queue while MOSIP processes the packet. When MOSIP issues the credential, mosip-api accepts the registration in OpenCRVS with its own system client (OPENCRVS_CLIENT_ID / OPENCRVS_CLIENT_SECRET, holding record.action.accept and record.read) — see MOSIP Deployment and Action confirmation.

  6. If not eligible, returns HTTP 200 with the registration number for immediate acceptance.

Birth correction handler

The onBirthCorrectionActionHandler in src/api/events/handler.ts handles two scenarios:

  • UIN creation on correction: If the child has no existing NID and eligibility rules pass, a new packet is sent to MOSIP via mosipInteropClient.register(...).

  • Biographic update: If the child already has a NID, mosipInteropClient.updateBiographics(...) is called instead.

Death registration handler

The onMosipDeathRegisterHandler in src/api/registration/index.ts follows the same pattern:

  1. Evaluates eligibility via shouldForwardDeathRegistrationToMosip.

  2. If eligible, sends the deceased's information to MOSIP via mosipInteropClient.register(...) with UIN and death details.

  3. Returns HTTP 200 for immediate acceptance (death registration does not require the external validation work queue).

Eligibility rules

Eligibility rules are defined in src/events/mosip.ts.

shouldForwardBirthRegistrationToMosip

The birth registration is forwarded to MOSIP when:

  • The child has a date of birth.

  • At least one parent (mother or father) has been identity-verified or authenticated.

  • The child is under 10 years old (configurable via CHILD_MAX_AGE_YEARS_FOR_MOSIP).

shouldForwardDeathRegistrationToMosip

The death registration is forwarded to MOSIP when the informant or spouse (if the informant is the spouse) has been identity-verified or authenticated.

Identity verification on action (ID Auth)

Beyond the dedicated MOSIP register handlers, the general onBirthActionHandler and onDeathActionHandler in src/api/events/handler.ts fire on every event action (DECLARE, VALIDATE, REGISTER, etc.). They can be used to verify identity data submitted offline against the MOSIP ID Auth SDK when the system comes online.

In a production implementation, the handler would call mosipInteropClient.verifyNid() for each available individual:

The createMosipInteropClient

The MOSIP interoperability client is created using:

The token passed here only proves to mosip-api that the request came from OpenCRVS. It carries no scopes and is not used to confirm the registration — mosip-api authenticates with its own system client for that.

The client provides:

  • register(...) — Send a new packet for UIN creation

  • updateBiographics(...) — Send biographic updates for an existing VID

Asynchronous flow and the "Awaiting external validation" workqueue

When the handler returns HTTP 202, the record enters a Requested state and appears in the "Pending external validation" workqueue. This workqueue is configured in src/api/workqueue/workqueueConfig.ts:

To read more about configuring workqueues, see the technical guide on workqueues.

Debugging a record stuck in "Pending external validation"

A record stays in this workqueue when MOSIP never sends the credential back. MOSIP does not report failures, so first check with the MOSIP team whether the packet failed. When it did, an implementer has to close the record by hand:

  1. Find the pending transaction in mosip-api.

  2. Reject the registration in OpenCRVS.

  3. Remove the transaction from mosip-api.

The examples below use localhost. In a deployed environment, use https://gateway.<your-domain> instead of http://localhost:7070 and https://mosip-api.<your-domain> instead of http://localhost:2024. Auth and events are reached through the gateway, not directly.

Every command runs on your own machine, against the deployed APIs. Only the kubectl exec in step 1 runs inside the cluster.

1. Find the pending transaction

mosip-api keeps one row per record it is waiting for. The row holds the MOSIP transaction id, the OpenCRVS event_id and the registration number.

If you have a token with the record.search scope (a registrar has one), list the rows over HTTP. The integration's own token does not work here — it has no search scope, and the route answers 403:

Otherwise, read the SQLite database directly. It lives at SQLITE_DATABASE_PATH, which is /data/sqlite/mosip-api.db in the Helm chart and data/sqlite/mosip-api.db under the repository root in local development. The image has no sqlite3 command, so query it with Node:

Rows much older than a normal MOSIP round trip are the stuck ones. Take the id and the event_id of the row you want to close.

2. Get a token for the integration

Use the integration's own credentials, OPENCRVS_CLIENT_ID and OPENCRVS_CLIENT_SECRET. These are the values mosip-api is configured with, and a National System Admin can read them from the OpenCRVS Integrations page. The client has the record.read, record.action.accept and record.action.reject scopes, which is what steps 3 and 4 need.

The response contains the token in access_token. It is used as <SYSTEM_TOKEN> below.

Rejecting as the integration also keeps the audit trail honest: no registrar rejected the record, it was closed because MOSIP never answered.

3. Find the action to reject

Read the event and take the id of the REGISTER action that is still Requested:

The event document comes back under result.data.json. If you have jq, pipe the response through it to print the id directly:

Without jq, read the actions array yourself and take the id of the entry whose type is REGISTER and whose status is Requested.

If there is more than one such action, the record has been through registration before. Pick the one that no other action refers to in its originalActionId — that is the pending one.

4. Reject the registration

The record leaves the workqueue and is unassigned. Calling this again for the same action is safe: the second call returns the event unchanged.

5. Remove the transaction

Finally, drop the row so mosip-api stops waiting for it:

This route needs the record.register scope, which the integration's token has. If MOSIP does answer later, the callback no longer finds the transaction and is logged as an error instead of confirming the record.

Last updated