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
- Angular - The Authorization Code grant using the Angular framework
- Angular with the hosted backend - The Authorization Code grant using the Angular framework with the FusionAuth Angular SDK and the hosted backend
- Consents - Example using advanced1 registration forms and consents
- Deeplinking - Example returning users to the same page they logged in on
- Device grant - An example of the Device Authorization grant
- Express API - Express api which uses the Cookie Access Token
- Family management - Family management and consent creation
- FusionAuth SSO - Example of SSO between two different custom applications
- Gaming and device grant - Example using the Device Authorization grant to provide authentication to a game.
- Gatsby OAuth - An example of using Gatsby with the Authorization Code grant and PKCE
- Javascript JWT - JWT creation and decoding examples with javascript
- JWT Auth and a Microservices gateway - API gateway and microservices secured using JWT auth
- Magic links login - nextjs app which uses magic links for authentication
- Microservices gateway - API gateway and microservices
- Multi-tenant application - Two nodejs applications in different tenants, living in different domains.
- Next.js Single Sign-On - Single sign-on with Next.js and FusionAuth
- Node OAuth - Login with the Authorization Code grant
- React Native - The Authorization Code grant for a React Native mobile application
- React with an Express backend - The Authorization Code grant using the React framework with the FusionAuth React SDK and an Express backend
- React with the hosted backend - The Authorization Code grant using the React framework with the FusionAuth React SDK and the hosted backend
- Remix auth - Example using FusionAuth to provide auth for a Remix application
- Twitter login - Node/express app which uses Twitter for authentication
- User actions example - Corresponds to the user actions guide tutorial
- Vue.js - The Authorization Code grant using the Vue.js framework