Download the PHP package ptpn/ion-client without Composer

On this page you can find all versions of the php package ptpn/ion-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ion-client

PTPN ION Client

Official PHP/Laravel client SDK untuk mengonsumsi API ION SSO v2.

Latest Version on Packagist

Fitur

Instalasi

Install package melalui Composer:

Konfigurasi

Publish file konfigurasi ke project Laravel:

Setelah dipublish, file config/ion-client.php akan tersedia. Tambahkan environment variables berikut di .env:

Alur Autentikasi SSO

Package ini mengikuti alur redirect-based SSO dengan tiga step utama. Perhatikan bahwa client_identifier (secret) tidak lagi dikirim di Step 1 — secret hanya dikirim di Step 3 melalui back-channel.

Penting: client_identifier hanya muncul di Step 3 (JSON body). Ia tidak pernah muncul di URL, browser history, access log, atau header X-Client-Secret saat verify().

Penggunaan

Step 1 — Redirect User ke SSO Login

Gunakan method getLoginUrl() untuk membangun URL login SSO. URL ini aman dibagikan ke browser karena hanya mengandung client_key dan redirect_uri. Secret client_identifier tidak pernah muncul di URL.

Secara default, jika redirectUri tidak diberikan, akan digunakan ION_FRONTEND_URL/auth/callback.

SSO Callback

Setelah user berhasil login di ION SSO, SSO server akan redirect ke callback URL aplikasi client dengan membawa query parameter code. Package ini menyediakan method callback() yang menangani seluruh alur tersebut.

ION_ENABLED: Jika ION_ENABLED=false, method callback() akan melewati seluruh proses SSO dan langsung redirect ke frontend. Ini memungkinkan aplikasi consumer untuk menggunakan auth Laravel/default atau provider autentikasi lainnya. Gunakan IonClient::isEnabled() untuk mengecek status integrasi SSO di kode aplikasi.

  1. Menukar code dengan session_id dari SSO melalui verify().

    • Request ke POST /api/v2/auth/verify dengan body JSON:

    • client_identifier dikirim di body, bukan di URL atau header X-Client-Secret.
  2. Membuat session lokal Laravel dengan ID yang sama persis dengan SSO session ID.
  3. Mengambil data lengkap user dari SSO.
  4. Menyimpan data user ke session.
  5. Set cookie session ke browser.
  6. Redirect browser ke frontend.

Buat route callback di aplikasi Laravel:

Atau menggunakan Facade:

Debug: callback() mencatat event penting ke Laravel log pada level debug (misalnya kode masuk, hasil verify(), session ID yang diekstrak, kunci data session yang disimpan, konfigurasi cookie, dan tujuan redirect). Aktifkan APP_DEBUG=true atau channel log debug saat menganalisis masalah SSO.

Penting: session lokal dibuat dengan ID yang sama dengan SSO session ID. Hal ini diperlukan agar webhook logout dari SSO dapat menghapus session lokal berdasarkan ID tersebut.

Menggunakan Facade

Menggunakan Dependency Injection

Daftar Method

Method Endpoint Deskripsi
checkSession($sessionId) GET /api/v2/auth/check-session Cek apakah session SSO masih aktif.
verify($code) POST /api/v2/auth/verify Tukar auth code menjadi session ID + data user.
getSessionFullInfo($sessionId) POST /api/v2/client/session/full-info Ambil data session lengkap.
getUserRoles($sessionId, $application) POST /api/v2/client/user/roles Ambil daftar role user untuk app tertentu.
getLoginUrl($redirectUri, $extra) — Bangun URL redirect SSO login (Step 1). Hanya mengandung client_key + redirect_uri.
heartbeat($sessionId) POST /api/v2/client/heartbeat Pertahankan session tetap aktif.
logout($sessionId) POST /api/v2/client/logout Logout user session (trigger putus ke SSO).
callback($request) POST /api/v2/auth/verify + POST /api/v2/client/session/full-info Handle SSO callback, buat session lokal, set cookie, redirect ke frontend.

Header Wajib

Hampir semua request ke ION otomatis menyertakan header wajib:

Pengecualian: verify() (Step 3, back-channel token exchange) tidak mengirim header X-Client-Secret. Credential (client_key dan client_identifier) dikirim dalam JSON body sesuai flow SSO terbaru.

Struktur Data SSO

Berikut adalah struktur data yang dikembalikan oleh ION SSO dan cara menggunakannya di aplikasi client.

1. Request & Response Verifikasi (POST /auth/verify)

Method verify($code) mengirim request ke POST /auth/verify dengan body:

Response yang dikembalikan:

Field JSON Key Keterangan
User.SessionID user.session_id Session ID dari SSO
User.Email user.email Email user
Error error Pesan error jika gagal

2. Data User Lengkap (POST /client/session/full-info)

Method getSessionFullInfo($sessionId) mengembalikan data user lengkap:

Field JSON Key Tipe Keterangan
Username username string Username / NIK SAP
SessionID session_id string SSO Session ID
HashUserID hash_user_id string Hash ID user
NikSAP nik_sap string NIK SAP karyawan
UserRole user_role string Role user, delimiter ;
ExpiresAt expires_at datetime Waktu expired session
Locale locale string Bahasa, contoh: id, en
Name name string Nama lengkap
PositionName position_name string Nama jabatan
DepartmentName department_name string Nama departemen
UnitName unit_name string Nama unit
UnitCode unit_code string Kode unit
CompanyName company_name string Nama perusahaan
Gender gender bool Jenis kelamin
TelegramID telegram_id string ID Telegram
CellphoneNumber cellphone_number string Nomor HP
HashRecipientId recipient_id string Hash recipient ID
CompanyID company_id int64 ID perusahaan asli
UnitID unit_id int64 ID unit asli
DepartmentID department_id int64 ID departemen asli
PositionID position_id int64 ID jabatan asli
LevelElemen level_elemen uint8 Level elemen user

3. Data User untuk Frontend

Saat mengirim data user ke frontend, sebaiknya:

Contoh response ke frontend:

4. User Roles (POST /client/user/roles)

Method getUserRoles($sessionId, $application) mengembalikan:

Field JSON Key Keterangan
ApplicationCode application_code Kode aplikasi
UserRoles user_roles Role user, delimiter ;

Di PHP, role bisa diubah menjadi array dengan:

Catatan Tentang Login

Package client ini tidak menyediakan fitur login dengan username/password. Proses autentikasi pengguna (memasukkan kredensial) berjalan di sisi ION SSO melalui redirect/resmi SSO. Client hanya menyediakan:

Logout tetap disediakan agar aplikasi client dapat memberitahu ION SSO bahwa session pengguna harus dihapus.

Penanganan Error

Semua error HTTP maupun error dari response ION akan dilempar sebagai Ptpn\IonClient\Exceptions\IonClientException. Pesan error akan diambil dari field message atau error pada response JSON ION jika tersedia.

Testing

Jalankan PHPUnit setelah menginstall dependency:

License

Package ini dirilis di bawah lisensi MIT.


All versions of ion-client with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
guzzlehttp/guzzle Version ^6.5|^7.0
illuminate/http Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ptpn/ion-client contains the following files

Loading the files please wait ...