PHPackages                             hawk-hhg/hawki-client-backend - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. hawk-hhg/hawki-client-backend

ActiveProject[HTTP &amp; Networking](/categories/http)

hawk-hhg/hawki-client-backend
=============================

A lightweight PHP backend for using HAWKI's external apps; that provides a secure, encrypted connection to your HAWKI instance.

1.1.0(7mo ago)078Apache-2.0TypeScriptPHP ^8.2CI passing

Since Oct 15Pushed 6mo agoCompare

[ Source](https://github.com/hawk-digital-environments/hawki-client-backend-php)[ Packagist](https://packagist.org/packages/hawk-hhg/hawki-client-backend)[ RSS](/packages/hawk-hhg-hawki-client-backend/feed)WikiDiscussions main Synced 1mo ago

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

HAWKI Client Backend (PHP)
==========================

[](#hawki-client-backend-php)

[![Latest Version](https://camo.githubusercontent.com/50eb0abfa075b6657fd69d2791a9599bd3b4b1d0ae79524789c81a9d16c4b268/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6861776b2d6868672f6861776b692d636c69656e742d6261636b656e642e737667)](https://packagist.org/packages/hawk-hhg/hawki-client-backend)[![Total Downloads](https://camo.githubusercontent.com/708ba45839cf7342859869731e531cba4d2fd5970b24625ca8015ff2aea54902/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6861776b2d6868672f6861776b692d636c69656e742d6261636b656e642e737667)](https://packagist.org/packages/hawk-hhg/hawki-client-backend)[![License](https://camo.githubusercontent.com/798509b4df525f56802b56f8096862487f08023e3d7561c68656f8dab10d0d6e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4170616368652d2d322e302d626c75652e737667)](https://github.com/hawk-digital-environments/hawki-client-backend-php/blob/main/LICENSE)[![Create new Release (PHP)](https://github.com/hawk-digital-environments/hawki-client-backend-php/actions/workflows/release.yml/badge.svg)](https://github.com/hawk-digital-environments/hawki-client-backend-php/actions/workflows/release.yml)

This package provides a secure, encrypted bridge between your PHP application and your HAWKI instance. It simplifies the process of managing user connections for HAWKI's external applications by handling API communication, data encapsulation, and cryptography.

Requirements
------------

[](#requirements)

- PHP: `^8.2`
- `psr/log`: `^3.0`
- `guzzlehttp/guzzle`: `^7.0`
- `hawk-hhg/hawki-crypto`: `^0.5.2`

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require hawk-hhg/hawki-client-backend
```

Complete documentation
----------------------

[](#complete-documentation)

To get a better understanding of how the library works, please refer to the complete documentation: [docs/index.md](_docs/index.md)

Quick Start: Creating a Configuration Endpoint
----------------------------------------------

[](#quick-start-creating-a-configuration-endpoint)

The primary role of this backend library is to provide a secure endpoint that your frontend HAWKI client can call to get its configuration. This configuration tells the frontend whether a user is already connected to HAWKI or needs to initiate a new connection.

The entire process is managed by the main `HawkiClientBackend` class.

### 1. Instantiate `HawkiClientBackend`

[](#1-instantiate-hawkiclientbackend)

First, create an instance of `HawkiClientBackend`. You'll need three pieces of sensitive information from your HAWKI application setup. It's crucial to store these as environment variables or secrets, not in version control. All three values will be provided to you when you execute the `php artisan ext-app:create` command in your HAWKI instance.

```
use Hawk\HawkiClientBackend\HawkiClientBackend;

// Load these values securely from your environment configuration.
$hawkiUrl = $_ENV['HAWKI_URL']; // e.g., 'https://your-hawki-instance.com'
$apiToken = $_ENV['HAWKI_API_TOKEN'];
$appPrivateKey = $_ENV['HAWKI_APP_PRIVATE_KEY'];

$hawkiClientBackend = new HawkiClientBackend(
    hawkiUrl: $hawkiUrl,
    apiToken: $apiToken,
    privateKey: $appPrivateKey
);
```

### 2. Get the Encrypted Client Configuration

[](#2-get-the-encrypted-client-configuration)

With your `HawkiClientBackend` instance ready, you can now retrieve the secure configuration for a given user.

The main `getClientConfig()` method handles everything. It automatically checks if a user connection exists in HAWKI.

- If a connection exists, it fetches, decrypts, and prepares the details.
- If not, it creates a new connection request.

Finally, it encrypts the entire configuration payload using the **frontend's public key** before returning it.

### 3. Example: A Full API Endpoint

[](#3-example-a-full-api-endpoint)

Here is a practical example of a PHP script that could serve as your API endpoint (e.g., `POST /api/hawki-config`). The HAWKI frontend client is designed to call an endpoint like this. When using our provided Javascript client, the `clientConfigUrl` expects the JSON encoded output of this method.

```
