Skip to content

JavaScript

We provide an official client for JavaScript. You can install it with npm:

npm install @fief/fief

Create a Fief client

The Fief client provides all the necessary methods to manage OAuth2 authentication, validate access tokens and refresh them.

const fief = new Fief({
  baseURL: 'https://fief.mydomain.com',  // (1)!
  clientId: 'YOUR_CLIENT_ID',  // (2)!
  clientSecret: 'YOUR_CLIENT_SECRET', // (3)!
});
  1. Base URL of your Fief tenant

    You can find it in the admin dashboard, in the Tenants list. More info

    Find base URL in admin dashboard

  2. ID of your Fief client

    You can find it in the admin dashboard, in the Clients list. More info

    Find Client ID in admin dashboard

    Info

    A first client is always created for you when you create your instance. When getting started, you should use this one.

  3. Secret of your Fief client

    You can find it in the admin dashboard, in the Clients list. More info

    Find Client Secret in admin dashboard

    Info

    A first client is always created for you when you create your instance. When getting started, you should use this one.

Client secret is not safe in browser-based applications

If you build a browser-based application in JavaScript, the Client Secret is not safe: the end-user can easily find it in the source code.

To circumvent this, Fief allows to omit the client secret for clients with the public type. However, a PKCE code challenge will be required during the authorization flow.

What's next?

JavaScript being a vast ecosystem both for browsers and servers, integration paths can be quite different following your use-case.

To help you further, we provide you helpers and examples for popular JavaScript frameworks and technologies, like React.

Backend

Integrate with Express

Server-Side Rendering (SSR)

Integrate with Next.js

Frontend

Integrate in browser with plain JavaScript Integrate with React