Skip to main content

Fuse Auth Core (fuse-auth-core)

The fuse-auth-core package serves as the foundation for authentication and product API calls within the Fuse ecosystem. It contains code that handles the authentication of JWT tokens for various ecosystems such as Atlassian and Monday, as well as the creation of object representations of the app and the ability to build tokens or make product API calls.

By using this library, you can avoid multiple calls to the database to retrieve app settings and improve performance. The JWT V2 authorizer will query the database once during authentication and then attach the app details to the context. Subsequent downstream Lambda functions can create a RestClient instance using the context without needing to access the database again.

Table of Contents

Features

  • Authenticate JWT tokens
  • Create object representation/instance of the app
  • Generate JWT tokens (as app) or OAuth tokens (as user) for calling product APIs
  • Provide a RestClient for abstracting asApp and asUser product API calls
  • Use RestClientWrapper for easy access to the RestClient

Installing

Using npm:

$ npm install @appfire/fuse-auth-core

Once the package is installed, you can import the library using import:

import {
AppFactory,
AtlassianApp,
AtlassianRestClient,
AtlassianRestClientWrapper,
} from "@appfire/fuse-auth-core";

Example

Invoke Atlassian Product API from Lambda

If you are using the library in combination with JWT V2, you can use the AtlassianRestClientWrapper to avoid querying the database again. Otherwise, it will fetch the app details from the database and construct a RestClient object.

const [atlassianRestClient, userAccountId] = await AtlassianRestClientWrapper
.getInstance(_event);
const apiResponse = await atlassianRestClient.requestAsUser<string>(
`/rest/api/user/current`,
"get",
{},
userAccountId,
);
response = apiResponse.data;

You can find a complete working example of invoking a product API in the confluence-ref-app within the invokeProductApi() function.

JWT Authentication

An App may not be using it directly but this code is used at multiple places in Fuse Modules.

const app = await jwtAuthenticator(key, clientKey, token, {
pathname,
method,
query,
});

Create App Object

An App may not be using it directly but this code is used at multiple places in Fuse Modules.

const app = await AppFactory.getInstance(key, clientKey);