Download the PHP package bpjs/auth-client without Composer

On this page you can find all versions of the php package bpjs/auth-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 auth-client

🔐 Auth Service Client

Library autentikasi terpusat untuk microservices BPJS. Cukup install, tambah 1 baris middleware, beres!

PHP Version [Tests]() [License]()


📖 Daftar Isi


💡 Konsep

┌─────────────┐ │ User Service │ ← Satu-satunya tempat login & database user │ :8000 │ └──────┬───────┘ │ │ Token diverifikasi ke sini │ ┌──────┴──────────────────────────┐ │ │ │ ┌──────────┐ ┌──────────┐ │ │ │ HRM │ │ Ticket │ │ ← Service lain TIDAK perlu │ │ :8001 │ │ :8002 │ │ database user sendiri │ └──────────┘ └──────────┘ │ │ │ │ User login SEKALI, │ │ bisa akses SEMUA service │ └──────────────────────────────────┘

Keuntungan:


📋 Requirements


🚀 Installasi

1. via composer

  1. USER LOGIN (sekali) ┌─────────┐ POST /api/auth/login ┌──────────────┐ │ Browser │ ─────────────────────────────► │ User Service │ │ │ ◄───────────────────────────── │ :8000 │ └─────────┘ { token: "eyJ...", └──────────────┘ user: {...} }

  2. AKSES HRM ┌─────────┐ GET /api/payroll ┌──────────────┐ │ Browser │ Authorization: Bearer eyJ... │ HRM Service │ │ │ ────────────────────────────► │ :8001 │ └─────────┘ └──────┬───────┘ │
    1. VERIFIKASI TOKEN │ ┌────────────────────────────────┘ │ POST /api/auth/verify-token ▼ ┌──────────────┐ │ User Service │ │ :8000 │ └──────┬───────┘ │
      1. USER DATA │ ▼ ┌──────────────┐ │ HRM Service │ → $_SESSION['user'] │ :8001 │ → Controller └──────┬───────┘ │
      2. RESPONSE │ ▼ ┌─────────┐ │ Browser │ └─────────┘ Request 1: Token "xxx" → Cek cache: KOSONG → HTTP ke User Service (200ms) → Simpan cache (5 menit)

Request 2: Token "xxx" (dalam 5 menit) → Cek cache: ADA! → Langsung return (< 1ms) → TIDAK perlu HTTP request!

Environment Variables Variable Required Default Deskripsi AUTH_SERVICE_URL Ya http://localhost:8000 URL User Service AUTH_APP_KEY Ya - App Key dari User Service AUTH_APP_SECRET Ya - App Secret dari User Service AUTH_TIMEOUT Tidak 30 Timeout HTTP request (detik) AUTH_MAX_RETRIES Tidak 3 Max retry kalau gagal AUTH_TOKEN_SOURCE Tidak bearer Sumber token: bearer, cookie, header, query AUTH_COOKIE_NAME Tidak token Nama cookie (jika pakai cookie) AUTH_HEADER_NAME Tidak X-Auth-Token Nama custom header AUTH_REDIRECT_URL Tidak /login URL redirect jika tidak authenticated

Konfigurasi Middleware

Penggunaan Middleware

Mengakses User Data di Controller

Manual Usage (Tanpa Middleware)

Login/Logout

Cek Permission & Menu

Login di Frontend

API Reference AuthServiceClient Constructor

Parameters:

$config - Array konfigurasi

base_url - URL User Service

app_key - Application key

app_secret - Application secret

timeout - HTTP timeout (default: 30)

max_retries - Max retry (default: 3)

$cache - Optional CacheManager instance

Methods verifyToken(string $token): ?array Verifikasi token ke User Service

login(string $username, string $password, array $options = []): array Login user

logout(string $token): bool Logout user

refreshToken(string $refreshToken): array Refresh token expired

getUserMenus(int $userId, ?string $appCode = null): array Ambil menu user

checkMenuAccess(int $userId, string $menuCode): bool Cek akses menu

hasPermission(int $userId, string $permission): bool Cek permission user

AuthMiddlewareClient

Exceptions Exception HTTP Code Deskripsi AuthenticationException 401 Auth gagal TokenExpiredException 401 Token expired NetworkException 500 Network error UnauthorizedException 403 Tidak diizinkan 🐛 Error Handling Contoh Lengkap Error Handling

Response Format Sukses (200)

Token Tidak Ditemukan (401)

Token Expired (401)

Forbidden (403)

Troubleshooting Error: "Token tidak ditemukan" Penyebab: Token tidak dikirim atau format salah

Solusi:

Changelog v1.0.0 (2024-01-01) ✅ Initial release

✅ Token verification

✅ Login/Logout

✅ Permission check

✅ Menu access

✅ Caching support

✅ Middleware ready

📄 License MIT License

👥 Contributors Team BPJS Development


All versions of auth-client with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
ext-curl Version *
ext-json Version *
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 bpjs/auth-client contains the following files

Loading the files please wait ...