fusionauth / fusionauth-client
FusionAuth Client written in PHP
Installs: 399 015
Dependents: 1
Suggesters: 0
Security: 0
Stars: 21
Watchers: 13
Forks: 12
Open Issues: 10
Requires
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^10.5.8
- dev-develop
- 1.53.3
- 1.53.2
- 1.53.1
- 1.53.0
- 1.52.1
- 1.52.0
- 1.51.2
- 1.51.1
- 1.51.0
- 1.49.1
- 1.49.0
- 1.48.2
- 1.48.1
- 1.48.0
- 1.47.1
- 1.47.0
- 1.46.0
- 1.45.4
- 1.45.3
- 1.45.2
- 1.45.1
- 1.45.0
- 1.44.0
- 1.43.2
- 1.43.1
- 1.43.0
- 1.42.1
- 1.42.0
- 1.41.3
- 1.41.2
- 1.41.1
- 1.41.0
- 1.40.2
- 1.40.1
- 1.40.0
- 1.39.0
- 1.38.1
- 1.38.0
- 1.37.2
- 1.37.1
- 1.37.0
- 1.36.8
- 1.36.7
- 1.36.6
- 1.36.5
- 1.36.4
- 1.36.3
- 1.36.2
- 1.36.1
- 1.36.0
- 1.35.0
- 1.34.1
- 1.34.0
- 1.33.0
- 1.32.1
- 1.32.0
- 1.31.0
- 1.30.2
- 1.30.1
- 1.30.0
- 1.29.4
- 1.29.3
- 1.29.2
- 1.29.1
- 1.29.0
- 1.28.1
- 1.28.0
- 1.27.2
- 1.27.1
- 1.27.0
- 1.26.1
- 1.26.0
- 1.25.0
- 1.24.0
- 1.23.3
- 1.23.2
- 1.23.1
- 1.23.0
- 1.22.2
- 1.22.1
- 1.22.0
- 1.21.0
- 1.20.1
- 1.20.0
- 1.19.8
- 1.19.7
- 1.19.6
- 1.19.5
- 1.19.4
- 1.19.3
- 1.19.2
- 1.19.1
- 1.19.0
- 1.18.8
- 1.18.7
- 1.18.6
- 1.18.5
- 1.18.4
- 1.18.3
- 1.18.2
- 1.18.1
- 1.18.0
- 1.17.5
- 1.17.4
- 1.17.3
- 1.17.2
- 1.17.1
- 1.17.0
- 1.16.1
- 1.16.0
- 1.16.0-RC.1
- 1.15.8
- 1.15.7
- 1.15.6
- 1.15.5
- 1.15.4
- 1.15.3
- 1.15.2
- 1.15.1
- 1.15.0
- 1.14.0
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.1
- 1.12.0
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.1-RC.1
- 1.8.0-RC.1
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- dev-spencer/eng-1418/post-auth-bypass
- dev-main
- dev-1.53.3.maintenance
- dev-degroff/ENG-1/issue1
- dev-feature/usage_stats_client
- dev-spencer/eng-1365/fed-csrf-missing
- dev-spencer/eng-1600/scim-groups
- dev-spencer/eng-1623/saml-relaystate
- dev-spencer/eng-1692/remember-me
- dev-release-1.53.2
- dev-spencer/eng-1600/scim-atomic
- dev-1.53.1.maintenance
- dev-1.52.0.maintenance
- dev-1.51.1.maintenance
- dev-jj/release-workflow
- dev-feature/custom-themes
- dev-feature/custom-scopes
- dev-feature/touchup
- dev-1.48.2.maintenance
- dev-1.45.2.maintenance
- dev-1.43.0.maintenance
- dev-staging
- dev-1.45.0.maintenance
- dev-spencer/1738
- dev-spencer/1911/gis-one-tap
- dev-spencer/1939/gis-migration
- dev-1.42.0.maintenance
- dev-jto/max-ttl-1729
- dev-spencer/1912
- dev-spencer/1947
- dev-spencer/2010
- dev-spencer/test-refactor
- dev-spencer/778
- dev-jto/fixes1883
- dev-spencer/webauthn
- dev-defect-1918
- dev-johnathon/redirect_uri-wildcard
- dev-spencer/webauth-apple
- dev-spencer/issue-1699
- dev-spencer/issue-633
- dev-spencer/issue-971
- dev-spencer/issue-1547
- dev-spencer/issue-1676
- dev-rob/issue-1589
This package is auto-updated.
Last update: 2024-11-05 23:22:04 UTC
README
Intro
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.
For additional information and documentation on FusionAuth refer to https://fusionauth.io.
Install
The most preferred way to use the client library is to install the fusionauth/fusionauth-client
package via Composer by running the command below at your project root folder.
composer require fusionauth/fusionauth-client
Then, include the composer
autoloader in your PHP files.
require __DIR__ . '/vendor/autoload.php';
Examples
Set Up
First, you have to make sure you have a running FusionAuth instance. If you don't have one already, the easiest way to install FusionAuth is via Docker, but there are other ways. By default, it'll be running on localhost:9011
.
Then, you have to create an API Key in the admin UI to allow calling API endpoints.
You are now ready to use this library!
Error Handling
After every request is made, you need to check for any errors and handle them. To avoid cluttering things up, we'll omit the error handling in the next examples, but you should do something like the following.
// $result is the response of one of the endpoint invocations from the examples below if (!$result->wasSuccessful()) { echo "Error!" . PHP_EOL; echo "Got HTTP {$result->status}" . PHP_EOL; if (isset($result->errorResponse->fieldErrors)) { echo "There are some errors with the payload:" . PHP_EOL; var_dump($result->errorResponse->fieldErrors); } if (isset($result->errorResponse->generalErrors)) { echo "There are some general errors:" . PHP_EOL; var_dump($result->errorResponse->generalErrors); } }
Create the Client
To make requests to the API, first you need to create a FusionAuthClient
instance with the API Key created and the server address where FusionAuth is running.
$client = new FusionAuth\FusionAuthClient( apiKey: "<paste the API Key you generated here>", baseURL: "http://localhost:9011", // or change this to whatever address FusionAuth is running on );
Create an Application
To create an Application, use the createApplication()
method.
$result = $client->createApplication( applicationId: null, // Leave this empty to automatically generate the UUID request: [ 'application' => [ 'name' => 'ChangeBank', ], ], ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response var_dump($result->successResponse->application);
Check the API docs for this endpoint
Adding Roles to an Existing Application
To add roles to an Application, use createApplicationRole()
.
$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, ], ], ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response var_dump($result->successResponse->role);
Check the API docs for this endpoint
Retrieve Application Details
To fetch details about an Application, use retrieveApplication()
.
$result = $client->retrieveApplication( applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc', ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response var_dump($result->successResponse->application);
Check the API docs for this endpoint
Delete an Application
To delete an Application, use deleteApplication()
.
$result = $client->deleteApplication( applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc', ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response // Note that $result->successResponse will be empty
Check the API docs for this endpoint
Lock a User
To prevent a User from logging in, use deactivateUser()
.
$result = $client->deactivateUser( 'fa0bc822-793e-45ee-a7f4-04bfb6a28199', ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response
Check the API docs for this endpoint
Registering a User
To register a User in an Application, use register()
.
The code below also adds a customer
role and a custom appBackgroundColor
property to the User Registration.
$result = $client->register( userId: 'fa0bc822-793e-45ee-a7f4-04bfb6a28199', request: [ 'registration' => [ 'applicationId' => 'd564255e-f767-466b-860d-6dcb63afe4cc', 'roles' => [ 'customer', ], 'data' => [ 'appBackgroundColor' => '#096324', ], ], ], ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response
Check the API docs for this endpoint
Questions and support
If you find any bugs in this library, please open an issue. Note that changes to the FusionAuthClient
class have to be done on the FusionAuth Client Builder repository, which is responsible for generating that file.
But if you have a question or support issue, we'd love to hear from you.
If you have a paid plan with support included, please open a ticket in your account portal. Learn more about paid plan here.
Otherwise, please post your question in the community forum.
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, 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.
Upgrade Policy
This library is built automatically to keep track of the FusionAuth API, and may also receive updates with bug fixes, security patches, tests, code samples, or documentation changes.
These releases may also update dependencies, language engines, and operating systems, as we'll follow the deprecation and sunsetting policies of the underlying technologies that it uses.
This means that after a dependency (e.g. language, framework, or operating system) is deprecated by its maintainer, this library will also be deprecated by us, and will eventually be updated to use a newer version.