# PHP Client Library The FusionAuth PHP Client library allows you to call FusionAuth from PHP applications. > For the index of this section of the site, see [llms.txt](https://4002.18-224-161-104.sslip.io/docs/llms.txt) The PHP client library allows you to integrate FusionAuth with your PHP application. Source code: * [https://github.com/FusionAuth/fusionauth-php-client](https://github.com/FusionAuth/fusionauth-php-client) ## Install the library 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. Packagist * [https://packagist.org/packages/fusionauth/fusionauth-client](https://packagist.org/packages/fusionauth/fusionauth-client) ```bash composer require fusionauth/fusionauth-client ``` Include composer autoloader ```php require __DIR__ . '/vendor/autoload.php'; ``` ## Usage Suggestions FusionAuth client libraries are a thin wrapper around the REST API. Client libraries are typically used in two different ways. First, they can be used to access the FusionAuth [APIs](https://4002.18-224-161-104.sslip.io/docs/apis.md) in a familiar format, leveraging language features like auto-completion. When used for this, they can be helpful to script FusionAuth configuration, automate common tasks, and create copies of existing applications, groups and more. To use the client libraries effectively in this way, it is helpful to review the source code of the client library and the API documentation, which contains the JSON structure. The API documentation is very thorough about the JSON objects it expects as part of the payload as well as what parameters are required when. Second, client libraries can exchange a token to let a user to log in via the Authorization Code Grant. This is a secondary use of these libraries. This process is best done by using a language specific OAuth library, which will work with FusionAuth. Here is a [community curated list of such libraries](https://oauth.net/code/). Client libraries do not currently provide higher level functionality such as token management. Here is an [open issue](https://github.com/FusionAuth/fusionauth-issues/issues/1674) detailing some requested higher level functionality. Please feel free to file an issue or upvote this one if you desire it. You can always directly call the REST API if the client library functionality doesn't work for you. All the client libraries use the [REST API](https://4002.18-224-161-104.sslip.io/docs/apis.md). In general, the request object will either be string parameters or a complex object depending on the type of API call being made. Any request object will be mapped by the library to a JSON object required by the corresponding API method. Examining the API documents for the operations you're trying to call will therefore be useful, especially if you are using language without static typing. The response object will typically contain: * a status corresponding to the HTTP status code returned by the API. It may also be -1 if no HTTP request was successfully made * a JSON success object if the call succeeded. * a JSON error object with an intelligible message if the status code is `4xx` or `5xx`. * an exception object if there was no HTTP request sent or there was no reasonable response from the server. ## Create the Client The following code assumes FusionAuth is running on `http://localhost:9011` and uses an API key `5a826da2-1e3a-49df-85ba-cd88575e4e9d`, you will need to supply your own API key, and if you are not running FusionAuth locally, your host parameter may be different. ```php $apiKey = "5a826da2-1e3a-49df-85ba-cd88575e4e9d"; $client = new FusionAuth\FusionAuthClient($apiKey, "http://localhost:9011"); ``` ## Login a user ```php $applicationId = "68364852-7a38-4e15-8c48-394eceafa601"; $request = array(); $request["applicationId"] = $applicationId; $request["loginId"] = "joe@fusionauth.io"; $request["password"] = "abc123"; $result = $client->login($request); if (!$result->wasSuccessful()) { // Error } {/* Hooray! Success */} ``` ## Example Apps * [PHP Drupal quickstart](https://github.com/FusionAuth/fusionauth-quickstart-php-drupal-web) - PHP Drupal quickstart tutorial showing how to integrate FusionAuth with a PHP Drupal application * [PHP JWT](https://github.com/FusionAuth/fusionauth-example-php-jwt) - JWT creation and decoding examples with the PHP firebase-jwt library * [PHP Laravel API quickstart](https://github.com/FusionAuth/fusionauth-quickstart-php-laravel-api) - PHP Laravel API quickstart tutorial showing how to integrate FusionAuth with a PHP Laravel API * [PHP Laravel quickstart](https://github.com/FusionAuth/fusionauth-quickstart-php-laravel-web) - PHP Laravel quickstart tutorial showing how to integrate FusionAuth with a PHP Laravel application * [PHP multi-tenant](https://github.com/FusionAuth/fusionauth-example-symfony-multitenant) - A Pied Piper multi-tenant video chat application * [PHP quickstart](https://github.com/FusionAuth/fusionauth-quickstart-php-web) - PHP quickstart tutorial showing how to integrate FusionAuth with a PHP web application * [Symfony 5 webapp](https://github.com/FusionAuth/fusionauth-example-symfony) - An Symfony 5 webapp using FusionAuth as the identity server * [Updating a legacy PHP app using a connector](https://github.com/FusionAuth/fusionauth-example-php-connector) - Updating a legacy PHP app to OAuth and migrating users * [Webhooks](https://github.com/FusionAuth/fusionauth-example-php-webhook) - Handling a breached password detection webhook with PHP * [Wordpress quickstart](https://github.com/FusionAuth/fusionauth-quickstart-wordpress-web) - Wordpress quickstart tutorial showing how to integrate FusionAuth with a Wordpress application ## Other PHP Libraries Here are other PHP libraries that may be useful. Some are community supported; please visit the library website to learn more. * WordPress OpenID Connect Plugin * [FusionAuth Provider for the PHP League's OAuth 2.0 Client](https://github.com/jerryhopper/oauth2-fusionauth) * [FusionAuth Provider for Laravel Socialite](https://github.com/SocialiteProviders/FusionAuth) ## Upgrade Policy Besides the releases made to keep track of the FusionAuth API as mentioned above, SDKs and Client Libraries may periodically 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 the libraries use. This means that after a language, framework, or operating system is deprecated by their own maintainer, our SDKs and Client Libraries that depend on it will also be deprecated by us, and will eventually be updated to use a newer version. For more information about upgrades, see our [Upgrade guide](https://4002.18-224-161-104.sslip.io/docs/operate/deploy/upgrade.md#upgrade-a-client-library). Related [Get Started FusionAuth QuickStart for Laravel API QuickStart integration of a Laravel API application using FusionAuth. php authentication](https://4002.18-224-161-104.sslip.io/docs/get-started/quickstarts/api/quickstart-php-laravel-api.md) [Get Started FusionAuth QuickStart for PHP QuickStart integration of PHP web application with FusionAuth. php authentication](https://4002.18-224-161-104.sslip.io/docs/get-started/quickstarts/web/quickstart-php-web.md) [SDKs PHP Example Apps Learn about example applications written in PHP. fusionauth php](https://4002.18-224-161-104.sslip.io/docs/sdks/examples/php.md) --- ## Other pages in SDKs > For the full index of this section, see [SDKs](https://4002.18-224-161-104.sslip.io/docs/llms-sdks.txt). - [Kotlin SDK for Android](https://4002.18-224-161-104.sslip.io/docs/sdks/android-sdk.md): The FusionAuth Android SDK allows you to add different OAuth2 and OpenID Connect functionalities to your Android application. It's a highly standardized and simplified starting point for developers to easily integrate FusionAuth in their own custom Android mobile apps by taking care of all the dependencies. - [Angular SDK](https://4002.18-224-161-104.sslip.io/docs/sdks/angular-sdk.md): The FusionAuth Angular SDK allows you to add login, logout and registration functionality to your Angular application. - [Example Apps](https://4002.18-224-161-104.sslip.io/docs/sdks/examples.md): Learn about example applications using FusionAuth. - [Go Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/go.md): The FusionAuth Go Client library allows you to call FusionAuth from Go applications. - [Java Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/java.md): The FusionAuth Java Client library allows you to call FusionAuth from Java applications. - [.NET Core Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/netcore.md): The FusionAuth .NET Core Client library allows you to call FusionAuth from a .NET Core application. - [Python Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/python.md): The FusionAuth Python Client library allows you to call FusionAuth from Python applications. - [React SDK](https://4002.18-224-161-104.sslip.io/docs/sdks/react-sdk.md): The FusionAuth React SDK allows you to add login, logout and registration functionality to your React application. - [Ruby Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/ruby.md): The FusionAuth Ruby Client library allows you to call FusionAuth from Ruby applications. - [Swift SDK for iOS](https://4002.18-224-161-104.sslip.io/docs/sdks/swift-sdk.md): Create iOS mobile apps with FusionAuth-based authentication using the Swift SDK. - [TypeScript Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/typescript.md): The FusionAuth Typescript Client library allows you to call FusionAuth from JavaScript and Typescript applications. - [Vue SDK](https://4002.18-224-161-104.sslip.io/docs/sdks/vue-sdk.md): The FusionAuth Vue SDK allows you to add login, logout and registration functionality to your Vue application.