zulhilmirahman/mydigitalid-laravel
Composer 安装命令:
composer require zulhilmirahman/mydigitalid-laravel
包简介
MyDigitalID (Malaysia) OIDC authentication integration for Laravel
README 文档
README
Laravel package for integrating Malaysia's MyDigitalID (Keycloak-based OIDC) authentication into any Laravel application.
Requirements
- PHP 8.1+
- Laravel 10, 11, 12, or 13
Installation
composer require zulhilmirahman/mydigitalid-laravel
Publish the config file:
php artisan vendor:publish --tag=mydigitalid-config
Configuration
1. Environment variables
# Required — the package throws a RuntimeException on boot if any of these are missing OIDC_ENABLED=true OIDC_CLIENT_ID=your-client-id OIDC_CLIENT_SECRET=your-client-secret OIDC_REALM=your-realm # Optional — defaults shown OIDC_BASE_URL=https://sso.digital-id.my OIDC_REDIRECT_URI="${APP_URL}/mydid/login/callback" # Optional — override individual endpoints only if the auto-built defaults are incorrect # Auto-built pattern: {OIDC_BASE_URL}/realms/{OIDC_REALM}/protocol/openid-connect/{endpoint} # OIDC_URL_AUTHORIZE= # OIDC_URL_ACCESS_TOKEN= # OIDC_URL_USERINFO= # OIDC_URL_LOGOUT= # Optional — defaults shown OIDC_USER_FIELD=nokp OIDC_REDIRECT_AFTER_LOGIN=/dashboard OIDC_LOGIN_URL=/login OIDC_POST_LOGOUT_REDIRECT=/
2. Config file
After publishing, edit config/mydigitalid.php to match your application:
// Eloquent model used to look up the local user 'user_model' => \App\Models\User::class, // DB column matched against the NRIC returned by MyDigitalID 'user_field' => env('OIDC_USER_FIELD', 'nokp'), // Keys returned by the userinfo endpoint 'nric_field' => 'nric', 'name_field' => 'nama', // Optional: set a specific auth guard (null uses the default guard) 'auth_guard' => null,
Routes registered
When OIDC_ENABLED=true, these routes are automatically registered:
| Method | URI | Name | Description |
|---|---|---|---|
| GET | /mydid/login/redirect |
mydigitalid.login |
Redirects user to MyDigitalID SSO |
| GET | /mydid/login/callback |
mydigitalid.callback |
Handles the OIDC callback |
| POST | /mydid/logout |
mydigitalid.logout |
Logs out locally and from MyDigitalID |
Usage in Blade
{{-- Login button --}} <a href="{{ route('mydigitalid.login') }}">Log Masuk dengan MyDigitalID</a> {{-- Logout form --}} <form method="POST" action="{{ route('mydigitalid.logout') }}"> @csrf <button type="submit">Log Keluar</button> </form>
How It Works
- User clicks the login link → redirected to MyDigitalID with a CSRF
statetoken. - MyDigitalID redirects back to
/mydid/login/callbackwith an authorizationcode. - The package exchanges the code for
access_token+id_token, then fetches user info. - The user's NRIC is matched against the local database using
user_field. - If a matching user is found, they are logged in via
Auth::login(). - If no match is found, the user is silently logged out of MyDigitalID and denied access.
Using the Service Directly
use ZulhilmiRahman\MyDigitalID\OIDCService; class MyController extends Controller { public function __construct(protected OIDCService $oidc) {} public function customFlow() { $url = $this->oidc->getAuthUrl('my-state-token'); // ... } }
License
MIT
zulhilmirahman/mydigitalid-laravel 适用场景与选型建议
zulhilmirahman/mydigitalid-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「SSO」 「laravel」 「Malaysia」 「oidc」 「mydigitalid」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zulhilmirahman/mydigitalid-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zulhilmirahman/mydigitalid-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zulhilmirahman/mydigitalid-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
iPay88 integration with Magento 2
Laravel 5.* Library for Malaysian states list
FPX multimedia components to be used for FPX Internet Banking applications in Laravel.
Laravel wrapper for Revenue Monster PHP SDK
RaudhahPay Gateway wrapper client
Simple Single Sign-On
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 48
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-12