Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/fusionauth/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DATABASE_USERNAME=fusionauth
DATABASE_PASSWORD=hkaLBM3RVnyYeYeqE3WI1w2e4Avpy0Wd5O3s3
FUSIONAUTH_APP_MEMORY=256M
FUSIONAUTH_APP_RUNTIME_MODE=development
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
53 changes: 53 additions & 0 deletions .github/fusionauth/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: '3'

services:
db:
image: postgres:16.0-alpine
environment:
PGDATA: /var/lib/postgresql/data/pgdata
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 5s
timeout: 5s
retries: 5
networks:
- db_net
restart: unless-stopped
volumes:
- db_data:/var/lib/postgresql/data

fusionauth:
image: fusionauth/fusionauth-app:latest
depends_on:
db:
condition: service_healthy
environment:
DATABASE_URL: jdbc:postgresql://db:5432/fusionauth
DATABASE_ROOT_USERNAME: ${POSTGRES_USER}
DATABASE_ROOT_PASSWORD: ${POSTGRES_PASSWORD}
DATABASE_USERNAME: ${DATABASE_USERNAME}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
FUSIONAUTH_APP_MEMORY: ${FUSIONAUTH_APP_MEMORY}
FUSIONAUTH_APP_RUNTIME_MODE: ${FUSIONAUTH_APP_RUNTIME_MODE}
FUSIONAUTH_APP_SILENT_MODE: true
FUSIONAUTH_APP_URL: http://fusionauth:9011
FUSIONAUTH_APP_KICKSTART_FILE: /usr/local/fusionauth/kickstart.json
SEARCH_TYPE: database
networks:
- db_net
restart: unless-stopped
ports:
- 9011:9011
volumes:
- fusionauth_config:/usr/local/fusionauth/config
- ./kickstart.json:/usr/local/fusionauth/kickstart.json

networks:
db_net:
driver: bridge

volumes:
db_data:
fusionauth_config:
46 changes: 46 additions & 0 deletions .github/fusionauth/kickstart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"variables": {
"applicationid": "e9fdb985-9173-4e01-9d73-ac2d60d1dc8e",
"apiKey": "72a8c464b86c3c9098c33da73f471b8a0352f6e14087ddc3",
"asymmetricKeyId": "#{UUID()}",
"defaultTenantId": "d7d09513-a3f5-401c-9685-34ab6c552453",
"adminEmail": "[email protected]",
"adminPassword": "password"
},
"apiKeys": [
{
"key": "#{apiKey}",
"description": "Unrestricted API key"
}
],
"requests": [
{
"method": "POST",
"url": "/api/key/generate/#{asymmetricKeyId}",
"tenantId": "#{defaultTenantId}",
"body": {
"key": {
"algorithm": "RS256",
"name": "For GitHub Actions",
"length": 2048
}
}
},
{
"method": "POST",
"url": "/api/user/registration",
"body": {
"user": {
"email": "#{adminEmail}",
"password": "#{adminPassword}"
},
"registration": {
"applicationId": "#{FUSIONAUTH_APPLICATION_ID}",
"roles": [
"admin"
]
}
}
}
]
}
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test Library

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up FusionAuth
working-directory: .github/fusionauth
run: docker compose up -d

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Waiting for FusionAuth App
run: timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9011)" != "200" ]]; do sleep 5; done' || false

- name: Run test suite
run: composer run test
130 changes: 102 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,140 @@
## FusionAuth PHP Client ![semver 2.0.0 compliant](http://img.shields.io/badge/semver-2.0.0-brightgreen.svg?style=flat-square)
If you're integrating FusionAuth with a PHP application, this library will speed up your development time.
# FusionAuth PHP Client ![semver 2.0.0 compliant](http://img.shields.io/badge/semver-2.0.0-brightgreen.svg?style=flat-square)

For additional information and documentation on FusionAuth refer to [https://fusionauth.io](https://fusionauth.io).

### Example Usage
## Intro

#### Install the Code
If you're integrating FusionAuth with a PHP application, this library will speed up your development time. Please also make sure to check our [SDK Usage Suggestions page](https://fusionauth.io/docs/sdks/#usage-suggestions).

To use the client library on your project simply copy the PHP source files from the `src` directory to your project or the following
Composer package.
For additional information and documentation on FusionAuth refer to [https://fusionauth.io](https://fusionauth.io).

Packagist
## Install

* https://packagist.org/packages/fusionauth/fusionauth-client
The most preferred way to use the client library is to install the [`fusionauth/fusionauth-client`](https://packagist.org/packages/fusionauth/fusionauth-client) package via Composer by running the command below at your project root folder.

```bash
composer require fusionauth/fusionauth-client
```

Include composer autoloader
Then, include the autoloader in your PHP files.

```PHP
```php
require __DIR__ . '/vendor/autoload.php';
```

#### Create the Client
## Questions and support

If you have a question or support issue regarding this client library, we'd love to hear from you.

If you have a paid edition with support included, please [open a ticket in your account portal](https://account.fusionauth.io/account/support/). Learn more about [paid editions here](https://fusionauth.io/pricing).

Otherwise, please [post your question in the community forum](https://fusionauth.io/community/forum/).

## Examples

```PHP
### Create the Client

```php
$apiKey = "5a826da2-1e3a-49df-85ba-cd88575e4e9d";
$client = new FusionAuth\FusionAuthClient($apiKey, "http://localhost:9011");
```

#### Login a user
### Create an Application

```php
$result = $client->createApplication(
applicationId: null, // Leave this empty to automatically generate the UUID
request: [
'application' => [
'name' => 'ChangeBank',
],
],
);
if (!$result->wasSuccessful()) {
// Check HTTP Code at $result->status
// and error message at $result->errorResponse
}

// Hooray! Success
var_dump($result->successResponse->application);
```

```PHP
$applicationId = "68364852-7a38-4e15-8c48-394eceafa601";
### Adding Roles to an Existing Application

```php
$result = $client->createApplicationRole(
applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc', // Existing Application Id
roleId: null, // Leave this empty to automatically generate the UUID
request: [
'role' => [
'name' => 'customer',
'description' => 'Default role for regular customers',
'isDefault' => true,
],
],
);

$request = array();
$request["applicationId"] = $applicationId;
$request["loginId"] = "[email protected]";
$request["password"] = "abc123";
$result = $client->login($request);
if (!$result->wasSuccessful()) {
// Error
// Check HTTP Code at $result->status
// and error message at $result->errorResponse
}

// Hooray! Success
var_dump($result->successResponse->role);
```

## Questions and support
### Retrieve Application Details

If you have a question or support issue regarding this client library, we'd love to hear from you.
```php
$result = $client->retrieveApplication(
applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc',
);

If you have a paid edition with support included, please [open a ticket in your account portal](https://account.fusionauth.io/account/support/). Learn more about [paid editions here](https://fusionauth.io/pricing).
if (!$result->wasSuccessful()) {
// Check HTTP Code at $result->status
// and error message at $result->errorResponse
}

Otherwise, please [post your question in the community forum](https://fusionauth.io/community/forum/).
// Hooray! Success
var_dump($result->successResponse->application);
```

### Delete an Application

```php
$result = $client->deleteApplication(
applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc',
);

if (!$result->wasSuccessful()) {
// Check HTTP Code at $result->status
// and error message at $result->errorResponse
}

// Hooray! Success
// Note that $result->successResponse will be empty
```

### Lock a User

```php
$result = $client->deactivateUser(
'fa0bc822-793e-45ee-a7f4-04bfb6a28199',
);

if (!$result->wasSuccessful()) {
// Check HTTP Code at $result->status
// and error message at $result->errorResponse
}

// Hooray! Success
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/FusionAuth/fusionauth-php-client.

Note: if you want to change the `FusionAuthClient` class, you have to do it on the [FusionAuth Client Builder repository](https://github.com/FusionAuth/fusionauth-client-builder/blob/master/src/main/client/php.client.ftl), which is responsible for generating all client libraries we support.

## License

This code is available as open source under the terms of the [Apache v2.0 License](https://opensource.org/licenses/Apache-2.0).
This code is available as open source under the terms of the [Apache v2.0 License](https://opensource.org/blog/license/apache-2-0).

2 changes: 1 addition & 1 deletion build.savant
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* language governing permissions and limitations under the License.
*/

project(group: "io.fusionauth", name: "fusionauth-php-client", version: "1.46.0", licenses: ["ApacheV2_0"]) {
project(group: "io.fusionauth", name: "fusionauth-php-client", version: "1.49.0", licenses: ["ApacheV2_0"]) {
workflow {
fetch {
cache()
Expand Down
Loading