FusionAuth JavaScript Client Library

The following client library is now deprecated in favor of the typescript client, as it can do everything this project can but with better type support and examples.

JavaScript Client Library

The JavaScript client library allows you to integrate FusionAuth with your JavaScript application.

Source Code:

Please note that if you will be using this client library in front end code such as a web browser you will not have a secure way to store an API key. You may optionally pass a value of null for the API key parameter and still make API requests that do not require an API key.

The following code assumes FusionAuth is running on http://localhost:9011 and uses an API key 6b87a398-39f2-4692-927b-13188a81a9a3, you will need to supply your own API key, and if you are not running FusionAuth locally, your host parameter may be different.

Here is an example of using the retrieveUserByEmail method to retrieve a User by an email address.

<html>
  <head>
    <script src="../lib/ClientResponse.js"></script>
    <script src="../lib/RESTClient.js"></script>
    <script src="../lib/FusionAuthClient.js"></script>
    <script>
      var client = new FusionAuthClient('6b87a398-39f2-4692-927b-13188a81a9a3', 'http://localhost:9011');
      function handleResponse (clientResponse) {
        console.info(JSON.stringify(clientResponse.successResponse.user, null, 2));
      }
      // Retrieve User by Email Address
      client.retrieveUserByEmail('user@example.com', handleResponse);
    </script>
  </head>
  <body>
    Super Awesome Application
  </body>
</html>

Client Authentication

You may use this client library in an application that cannot securely store secrets, such as a native mobile application or a single page application running in the browser.

In this scenario, you should disable Require authentication in the FusionAuth Application configuration and use PKCE to secure communication with the Token endpoint.

You can use the exchangeOAuthCodeForAccessTokenUsingPKCE client method to do so.

Example Apps

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.