PHPackages                             xepeng/oauth-php - 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. xepeng/oauth-php

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

xepeng/oauth-php
================

Xepeng OAuth &amp; Integration PHP SDK

1.1.0(1mo ago)018MITPHPPHP ^7.4 || ^8.0

Since Feb 10Pushed 1mo agoCompare

[ Source](https://github.com/syaifudin21/xepeng-oauth-php)[ Packagist](https://packagist.org/packages/xepeng/oauth-php)[ RSS](/packages/xepeng-oauth-php/feed)WikiDiscussions main Synced today

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

Xepeng OAuth &amp; Integration PHP SDK
======================================

[](#xepeng-oauth--integration-php-sdk)

[![Version](https://camo.githubusercontent.com/dd58329e6a923a53561c83ac932237b7ea0b6cc313a12cc4c07d38bef38b6e61/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d312e312e302d626c7565)](https://packagist.org/packages/xepeng/oauth-php)[![PHP](https://camo.githubusercontent.com/e179af9555b4ff6db9113cae2b83cc29d401f82ee7e1842a860880d1ef6f14ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d677265656e)](https://php.net)[![License](https://camo.githubusercontent.com/df9ef5ebbc360b212bf361fcc971ca3855b214c20dd7aad432691210fac99575/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d6f72616e6765)](LICENSE)

Library PHP untuk integrasi dengan layanan Xepeng. SDK ini terdiri dari dua komponen utama:

- **OAuth SDK** - Autentikasi pengguna menggunakan OAuth 2.0 dengan PKCE
- **Integration SDK** - Integrasi API untuk mengelola pesanan dan tautan pembayaran

---

Persyaratan Sistem
------------------

[](#persyaratan-sistem)

KomponenMinimumPHP7.4 atau 8.0+Ekstensi JSONRequiredGuzzle HTTP7.0+---

Instalasi
---------

[](#instalasi)

### Via Composer

[](#via-composer)

```
composer require xepeng/oauth-php
```

### Manual Installation

[](#manual-installation)

Jika tidak menggunakan Composer, unduh source dan load secara manual:

```
require_once 'path/to/src/autoload.php';
// atau include satu per satu semua file di src/
```

---

Quick Start - OAuth
-------------------

[](#quick-start---oauth)

Contoh minimal untuk integrasi OAuth dalam 10 baris:

```
use Xepeng\OAuth\Client;

session_start();

$client = new Client([
    'client_id' => 'your-client-id',
    'client_secret' => 'your-client-secret',
    'redirect_uri' => 'https://your-app.com/callback',
]);

// Redirect ke halaman login Xepeng
if (!isset($_GET['code'])) {
    header('Location: ' . $client->getAuthorizationUrl());
    exit;
}

// Handle callback dan dapatkan token
$tokens = $client->handleCallback();
echo "Access Token: " . $tokens['access_token'];
```

---

Bagian 1: OAuth SDK
===================

[](#bagian-1-oauth-sdk)

1.1 Konfigurasi
---------------

[](#11-konfigurasi)

### Parameter Konfigurasi

[](#parameter-konfigurasi)

ParameterTipeRequiredDefaultDeskripsi`client_id`stringYa-Client ID dari dashboard Xepeng`client_secret`stringYa-Client Secret dari dashboard Xepeng`redirect_uri`stringYa-URL callback setelah autentikasi`env`stringTidak`development``development` atau `production``scopes`arrayTidak`['profile', 'email']`Scope OAuth yang diminta`base_url`stringTidakautoOverride base URL untuk OAuth`api_base_url`stringTidakautoOverride API base URL`storage_adapter`StorageInterfaceTidakSessionStorageAdapter storage kustom`auto_refresh`boolTidak`true`Auto-refresh token sebelum expired`refresh_buffer`intTidak`300`Detik sebelum expired untuk refresh### Environment URLs

[](#environment-urls)

```
// Development
'base_url' => 'https://staging-app.xepeng.com'
'api_base_url' => 'https://staging-api.xepeng.com'

// Production
'base_url' => 'https://app.xepeng.com'
'api_base_url' => 'https://api.xepeng.com'
```

---

1.2 Alur OAuth + PKCE
---------------------

[](#12-alur-oauth--pkce)

SDK ini menggunakan **OAuth 2.0 PKCE (Proof Key for Code Exchange)** untuk keamanan tambahan. Berikut step-by-step alur autentikasi:

```
┌─────────────────────────────────────────────────────────────────────────────┐
│                           ALUR OAUTH + PKCE                                 │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│  [1] GENERATE RANDOM STATE & PKCE                                            │
│      ├── Generate random state (43 chars)                                   │
│      ├── Generate code_verifier (64 chars)                                  │
│      └── Generate code_challenge (SHA256 + base64url encode)                │
│                                                                              │
│  [2] REDIRECT KE XEPENG                                                     │
│      GET https://app.xepeng.com/oauth/authorize                             │
│      ?client_id=xxx                                                         │
│      &redirect_uri=xxx                                                      │
│      &response_type=code                                                    │
│      &scope=profile+email                                                   │
│      &state=xxx                                                             │
│      &code_challenge=xxx                                                    │
│      &code_challenge_method=S256                                            │
│                                                                              │
│  [3] USER LOGIN DI XEPENG                                                   │
│      └── User authorize aplikasi                                            │
│                                                                              │
│  [4] REDIRECT BACK TO CALLBACK                                               │
│      GET https://your-app.com/callback?code=xxx&state=xxx                   │
│                                                                              │
│  [5] EXCHANGE CODE FOR TOKEN                                                │
│      POST /oauth/token                                                       │
│      {                                                                       │
│          grant_type: 'authorization_code',                                   │
│          code: 'xxx',                                                        │
│          redirect_uri: 'xxx',                                                │
│          client_id: 'xxx',                                                   │
│          client_secret: 'xxx',                                               │
│          code_verifier: 'xxx'  ← PKCE verifier untuk verifikasi             │
│      }                                                                       │
│                                                                              │
│  [6] RESPONSE                                                               │
│      {                                                                       │
│          access_token: 'xxx',                                               │
│          refresh_token: 'xxx',                                               │
│          expires_in: 3600,                                                   │
│          token_type: 'Bearer'                                               │
│      }                                                                       │
│                                                                              │
│  [7] STORE TOKENS                                                           │
│      └── Tokens disimpan di storage (session/redis/db)                     │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

```

### Mengapa PKCE?

[](#mengapa-pkce)

PKCE menambahkan lapisan keamanan dengan:

1. **Code Verifier** - Secret yang hanya diketahui client
2. **Code Challenge** - Hash dari verifier yang dikirim ke server
3. **Mencegah interception** -即使有人拦截了code，也无法兑换token tanpa verifier

---

1.3 Penggunaan Vanilla PHP
--------------------------

[](#13-penggunaan-vanilla-php)

### Contoh Lengkap

[](#contoh-lengkap)

```
