PHPackages                             zulhilmirahman/mydigitalid-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. zulhilmirahman/mydigitalid-laravel

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

zulhilmirahman/mydigitalid-laravel
==================================

MyDigitalID (Malaysia) OIDC authentication integration for Laravel

v1.0.0(4w ago)03MITPHPPHP ^8.1

Since May 12Pushed 4w agoCompare

[ Source](https://github.com/zulhilmixrahman/mydigitalid-laravel)[ Packagist](https://packagist.org/packages/zulhilmirahman/mydigitalid-laravel)[ RSS](/packages/zulhilmirahman-mydigitalid-laravel/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

MyDigitalID Laravel
===================

[](#mydigitalid-laravel)

Laravel package for integrating Malaysia's **MyDigitalID** (Keycloak-based OIDC) authentication into any Laravel application.

---

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10, 11, 12, or 13

---

Installation
------------

[](#installation)

```
composer require zulhilmirahman/mydigitalid-laravel
```

Publish the config file:

```
php artisan vendor:publish --tag=mydigitalid-config
```

---

Configuration
-------------

[](#configuration)

### 1. Environment variables

[](#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

[](#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
-----------------

[](#routes-registered)

When `OIDC_ENABLED=true`, these routes are automatically registered:

MethodURINameDescriptionGET`/mydid/login/redirect``mydigitalid.login`Redirects user to MyDigitalID SSOGET`/mydid/login/callback``mydigitalid.callback`Handles the OIDC callbackPOST`/mydid/logout``mydigitalid.logout`Logs out locally and from MyDigitalID---

Usage in Blade
--------------

[](#usage-in-blade)

```
{{-- Login button --}}
Log Masuk dengan MyDigitalID

{{-- Logout form --}}

    @csrf
    Log Keluar

```

---

How It Works
------------

[](#how-it-works)

1. User clicks the login link → redirected to MyDigitalID with a CSRF `state` token.
2. MyDigitalID redirects back to `/mydid/login/callback` with an authorization `code`.
3. The package exchanges the code for `access_token` + `id_token`, then fetches user info.
4. The user's NRIC is matched against the local database using `user_field`.
5. If a matching user is found, they are logged in via `Auth::login()`.
6. If no match is found, the user is silently logged out of MyDigitalID and denied access.

---

Using the Service Directly
--------------------------

[](#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
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance94

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

29d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7ac189a90f2d5fc435c14a023e05ac82dbe4f0e794d4bbabe821e97396e22f27?d=identicon)[zulhilmixrahman](/maintainers/zulhilmixrahman)

---

Tags

laravelSSOoidcMalaysiamydigitalid

### Embed Badge

![Health badge](/badges/zulhilmirahman-mydigitalid-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/zulhilmirahman-mydigitalid-laravel/health.svg)](https://phpackages.com/packages/zulhilmirahman-mydigitalid-laravel)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

76318.2M110](/packages/laravel-mcp)[api-platform/laravel

API Platform support for Laravel

59156.3k10](/packages/api-platform-laravel)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1232.2k16](/packages/fleetbase-core-api)[rahul900day/laravel-captcha

Different types of Captcha implementation for Laravel Application.

10920.2k](/packages/rahul900day-laravel-captcha)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
