Activepieces offers a frontend SDK that allows you to gather credentials from your users and establish connections within your Activepieces project, which can be named according to your preference. Additionally, Activepieces manages OAuth2 authentication by keeping tokens refreshed.

Identify User

Before using Activepieces SDK, you will need to setup your application so that you can identify your users to Activepieces.

Obtain Signing Key:

Signing keys are currently obtained by manually contacting the Activepieces team.

For security reasons, Activepieces does not store these keys. If a key is lost, a new one will need to be generated by contacting Activepieces again.

Generate User Token:

The signing key will be used to generate JWT tokens for the currently logged-in user on your website, which will then be sent to Activepieces to create a connection with the collected credentials.

To generate these tokens, you will need to add code in your backend and ensure the tokens are signed using the RS256 algorithm.

The signed tokens must include the “sub” and “exp” claims at a minimum:

{
	// Unique identification of your connection name.
	"sub": "the-user-id",

	// Expiry timestamp for token, such as 1 day from time of generation
	"exp": 1608603716
}

The following are snapshot code examples from different JWT libraries for creating the user token. You can also use this tool to generate a quick example: https://dinochiesa.github.io/jwt/.

NodeJs
const jwt = require('jsonwebtoken');

// JWT NumericDates specified in seconds:
const currentTime = Math.floor(Date.now() / 1000);
let token = jwt.sign({
        sub: "user-123",
        exp: currentTime + (24 * 60 * 60), // 1 day from now
    },
    process.env.ACTIVEPIECES_SIGNING_KEY, {
        algorithm: "RS256",
    }
);