mosip/php-auth-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mosip/php-auth-sdk

Composer 安装命令:

composer require mosip/php-auth-sdk

包简介

PHP SDK for MOSIP Authentication

README 文档

README

PHP SDK for MOSIP (Modular Open Source Identity Platform) Authentication Service. This library provides a simple interface to interact with MOSIP's authentication APIs, enabling demographic authentication, KYC verification, and OTP generation.

Features

  • Demographic Authentication - Authenticate individuals using demographic data (name, DOB, gender, etc.)
  • KYC Authentication - Know Your Customer verification with demographic and biometric data
  • OTP Generation - Generate OTP via email or phone
  • Response Decryption - Automatically decrypt and parse API responses
  • JWS Signing - Secure request signing using RS256
  • Encryption - RSA/OAEP and AES-256-GCM encryption support

Requirements

  • PHP >= 7.4
  • OpenSSL extension
  • JSON extension
  • cURL extension

Installation

Install via Composer (Recommended)

The package is available on Packagist:

composer require mosip/php-auth-sdk

Manual Installation

  1. Clone this repository:
git clone https://github.com/abdulbathish/php-auth-sdk.git
cd php-auth-sdk
  1. Install dependencies:
composer install

Configuration

Create a config.php file in the root directory:

<?php

$configDir = dirname(__FILE__);

return [
    'mosip_auth' => [
        'timestamp_format' => 'Y-m-d\TH:i:s',
        'ida_auth_version' => '1.0',
        'ida_auth_request_demo_id' => 'mosip.identity.auth',
        'ida_auth_request_kyc_id' => 'mosip.identity.kyc',
        'ida_auth_request_otp_id' => 'mosip.identity.otp',
        'ida_auth_env' => 'Staging',
        'authorization_header_constant' => 'Authorization',
        'partner_apikey' => 'YOUR_API_KEY',
        'partner_misp_lk' => 'YOUR_MISP_LK',
        'partner_id' => 'YOUR_PARTNER_ID',
    ],
    'mosip_auth_server' => [
        'ida_auth_domain_uri' => 'https://api-internal.YOUR_DOMAIN',
        'ida_auth_url' => 'https://api-internal.YOUR_DOMAIN/idauthentication/v1',
    ],
    'crypto_encrypt' => [
        'symmetric_key_size' => 256,
        'symmetric_nonce_size' => 128,
        'symmetric_gcm_tag_size' => 128,
        'encrypt_cert_path' => $configDir . '/keys/ida.pem',
        'decrypt_p12_file_path' => $configDir . '/keys/pa.p12',
        'decrypt_p12_file_password' => 'YOUR_P12_PASSWORD',
    ],
    'crypto_signature' => [
        'algorithm' => 'RS256',
        'sign_p12_file_path' => $configDir . '/keys/pa.p12',
        'sign_p12_file_password' => 'YOUR_P12_PASSWORD',
    ],
    'logging' => [
        'log_file_path' => $configDir . '/authenticator.log',
        'log_format' => '[%s] %s - %s - %s',
        'loglevel' => 'DEBUG',
    ],
];

Place your certificate files in the keys/ directory:

  • ida.pem - IDA certificate for encryption
  • pa.p12 - Partner certificate for signing and decryption

Usage

Basic Authentication (KYC)

<?php

require_once __DIR__ . '/vendor/autoload.php';

use MosipAuth\MOSIPAuthenticator;
use MosipAuth\Models\DemographicsModel;
use MosipAuth\Models\IdentityInfo;

$config = require __DIR__ . '/config.php';
$authenticator = new MOSIPAuthenticator($config);

$demographicsData = new DemographicsModel();
$demographicsData->name = [new IdentityInfo('eng', 'John Doe')];
$demographicsData->dob = '1990/01/01';
$demographicsData->gender = [new IdentityInfo('eng', 'male')];

$response = $authenticator->kyc(
    '9502435413',
    'UIN',
    $demographicsData,
    '',
    [],
    true
);

if ($response->getStatusCode() === 200) {
    $responseBody = json_decode($response->getBody()->getContents(), true);
    $decryptedResponse = $authenticator->decryptResponse($responseBody);
    print_r($decryptedResponse);
}

OTP Generation

$response = $authenticator->genotp(
    '9502435413',
    'UIN',
    '',
    true,  // email
    true   // phone
);

$responseBody = json_decode($response->getBody()->getContents(), true);
$transactionId = $responseBody['transactionID'];

Authentication with OTP

$response = $authenticator->kyc(
    '9502435413',
    'UIN',
    $demographicsData,
    '123456',  // OTP value
    [],
    true,
    $transactionId  // Transaction ID from OTP generation
);

API Reference

MOSIPAuthenticator

__construct($config, $logger = null)

Initialize the authenticator with configuration.

auth($individualId, $individualIdType, $demographicData = null, $otpValue = '', $biometrics = [], $consent = false, $txnId = '')

Perform demographic authentication.

kyc($individualId, $individualIdType, $demographicData = null, $otpValue = '', $biometrics = [], $consent = false, $txnId = '')

Perform KYC authentication.

genotp($individualId, $individualIdType, $txnId = '', $email = false, $phone = false)

Generate OTP via email or phone.

decryptResponse($responseBody)

Decrypt and parse the API response.

Models

DemographicsModel

Represents demographic data for authentication:

  • name - Array of IdentityInfo
  • dob - Date of birth (format: YYYY/MM/DD)
  • gender - Array of IdentityInfo
  • phoneNumber - Phone number
  • emailId - Email address
  • addressLine1, addressLine2, addressLine3 - Address lines
  • location1, location2, location3 - Location information
  • postalCode - Postal code
  • fullAddress - Full address

IdentityInfo

Represents language-value pairs:

  • language - Language code (e.g., 'eng', 'ara')
  • value - The actual value

License

Mozilla Public License Version 2.0

Author

Abdul Bathish

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

mosip/php-auth-sdk 适用场景与选型建议

mosip/php-auth-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Authentication」 「sdk」 「otp」 「kyc」 「mosip」 「demographic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mosip/php-auth-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mosip/php-auth-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 mosip/php-auth-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2025-11-19