PHP code example of blpid / connectidn-php

1. Go to this page and download the library: Download blpid/connectidn-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

blpid / connectidn-php example snippets


use BSSN\ConnectIDN\ConnectIDN;
use BSSN\ConnectIDN\ConnectIDNConfig;

$config = new ConnectIDNConfig(
    clientId:     'YOUR_CLIENT_ID',
    clientSecret: 'YOUR_CLIENT_SECRET',
    redirectUri:  'https://yourapp.com/auth/callback',
);

$connectidn = new ConnectIDN($config);

// auth/login.php
$connectidn->authenticate(); // redirect otomatis ke ConnectIDN

// auth/callback.php
session_start();

$user = $connectidn->authenticate();

RequireAuth::store($user); // simpan ke session dengan aman
header('Location: /dashboard');
exit;

use BSSN\ConnectIDN\RequireAuth;

// Di awal halaman yang perlu login
RequireAuth::guard('/auth/login'); // redirect ke login jika belum autentikasi

$user = RequireAuth::user(); // ambil data user dari session
echo 'Halo, ' . htmlspecialchars($user['name']);

// auth/logout.php
session_start();

$idToken = $_SESSION['connectidn_id_token'] ?? null;
RequireAuth::clear(); // hapus session user

$connectidn->logout($idToken ?? '', 'https://yourapp.com');

echo $connectidn->loginButton('/auth/login', logoSrc: '/images/logo.png');
bash
composer