Panduan Integrasi SSO Dirzen Account

Dirzen Account SSO Integration Guide

1. Persiapan Kredensial / Credential Preparation

ID: Sebelum memulai pengkodean, aplikasi klien harus didaftarkan ke dalam database pusat (tabel projects). Anda akan membutuhkan dua kredensial utama:

EN: Before starting to code, the client application must be registered in the central database (projects table). You will need two main credentials:

2. Alur Login (Frontend) / Login Flow (Frontend)

ID: Jangan membuat form login sendiri di aplikasi klien. Arahkan pengguna ke portal Dirzen Account dengan menyertakan parameter client_id dan redirect_uri.

EN: Do not build your own login form in the client app. Redirect users to the Dirzen Account portal, passing the client_id and redirect_uri parameters.

Format URL:

https://auth.dirzendigital.com/login?client_id=YOUR_CLIENT_ID&redirect_uri=https://proyek-baru.dirzendigital.com/callback

ID: Setelah pengguna berhasil login, Dirzen Account akan mengarahkan pengguna kembali ke redirect_uri dengan menambahkan parameter token.

EN: Once the user successfully logs in, Dirzen Account will redirect the user back to the redirect_uri appending a token parameter.

Hasil Redirect / Redirect Result:

https://proyek-baru.dirzendigital.com/callback?token=1a2b3c4d5e...

3. Verifikasi Token (Backend) / Token Verification (Backend)

ID: Token yang diterima di URL belum bisa dipercaya sepenuhnya. Backend aplikasi klien harus memvalidasi token tersebut ke server SSO menggunakan client_secret.

EN: The token received in the URL cannot be fully trusted yet. The client application's backend must validate the token against the SSO server using the client_secret.

Endpoint: POST https://auth.dirzendigital.com/api/verify.php

Payload (JSON):

{
    "token": "1a2b3c4d5e...",
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET"
}

ID: Jika valid, server akan merespons dengan data pengguna.

EN: If valid, the server will respond with the user data.

Respons Sukses / Success Response:

{
    "status": "success",
    "message": "Token valid.",
    "data": {
        "user": {
            "id": 1,
            "email": "user@email.com",
            "full_name": "Nama Pengguna"
        },
        "expires_at": "2026-07-23 10:00:00"
    }
}

4. Contoh Kode Klien (PHP) / Client Code Example (PHP)

ID: Berikut adalah contoh bagaimana backend aplikasi klien menangkap token dari URL dan memvalidasinya.

EN: Here is an example of how the client application's backend captures the token from the URL and validates it.

<?php
// Tangkap token dari parameter URL (?token=...)
// Capture token from URL parameter
$token = $_GET['token'] ?? null;

if (!$token) {
    die("Akses ditolak. Token tidak ditemukan. / Access denied. Token not found.");
}

// Persiapkan data untuk dikirim ke auth.dirzendigital.com
// Prepare data to send to auth.dirzendigital.com
$authServerUrl = 'https://auth.dirzendigital.com/api/verify.php';
$payload = json_encode([
    'token' => $token,
    'client_id' => 'APP_ID_ANDA', 
    'client_secret' => 'APP_SECRET_ANDA'
]);

// Lakukan request cURL ke server SSO
// Perform cURL request to SSO server
$ch = curl_init($authServerUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$responseData = json_decode($response, true);

if ($httpCode === 200 && $responseData['status'] === 'success') {
    // Validasi Sukses: Simpan sesi pengguna di aplikasi ini
    // Validation Success: Save user session in this application
    
    session_start();
    $_SESSION['user_id'] = $responseData['data']['user']['id'];
    $_SESSION['user_name'] = $responseData['data']['user']['full_name'];
    $_SESSION['user_email'] = $responseData['data']['user']['email'];
    
    // Arahkan ke halaman utama aplikasi / Redirect to main app page
    header("Location: /dashboard.php");
    exit;
} else {
    // Validasi Gagal / Validation Failed
    die("Login gagal: " . ($responseData['message'] ?? 'Token tidak valid.'));
}
?>