Installing the Connect SDK

SDK Installation

You can install the Paragon SDK into your site with a small snippet of JavaScript:

JavaScript
JavaScript
<script
type="text/javascript"
src="https://cdn.useparagon.com/latest/sdk/index.js"
></script>

This should go anywhere within the <body> element of your site, wherever you include external scripts.

The Paragon SDK gives you access to the Paragon global, which you can access as window.paragon or simply paragon.

Setup

Before using the Paragon SDK, you'll need to set up your application to verify the identity of your users to the SDK.

Paragon verifies the identity of your users using the authentication system you're already using, including managed services like Firebase Authentication, Auth0, and MemberStack. Some backend code may be required if your application implements its own sign-in and registration.

If your application implements its own authentication backend, follow the steps in Setup with your own authentication backend.

If you use a managed authentication service like Firebase Authentication or Auth0, follow the steps in Setup with a managed authentication service.

Setup with your own authentication backend

If you use your own backend server to manage authentication, you'll first need to complete the following steps:

1. Generate a Paragon Signing Key

To generate a Signing Key, go to Settings > Signing Keys in your Paragon dashboard. You should store this key in an environment secrets file.

For security reasons, we don’t store your Private Key and cannot show it to you again, so we recommend you download the key and store it someplace secure.

2. Sign a JWT

Next, you'll need a library in your target language to sign JWTs with RS256. You can find one in your language at https://jwt.io/.

If your application is a fully client-rendered single-page app, you may have to create and use an additional API endpoint to retrieve a signed JWT (or reuse an existing endpoint that handles authentication or user info).

The signed JWT/Paragon user token minimally must include the sub, iat, and exp claims:

JavaScript
JavaScript
{
// Uniquely identifying key for a user
"sub": "the-user-id",
// Issue timestamp, should be the current time
"iat": 1608600116
// Expiry timestamp for token, such as 1 hour from time of signature (iat)
"exp": 1608603716
}

3. Call paragon.authenticate()

You'll call paragon.authenticate in your view with a JWT signed by your backend using the library chosen in Step 2. This JWT is the Paragon user token.

paragon.authenticate(
// You can find your project ID in the Overview tab of any Integration
"38b1f170-0c43-4eae-9a04-ab85325d99f7",
// See Setup for how to encode your user token
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.ey..."
);

Example Implementation: A Node.js and Express app using Handlebars view templating

  1. Adding middleware to sign the JWT and include it in the response context

    // server.js - Adding middleware to sign an authenticated user's token
    const jwt = require('jsonwebtoken');
    app.use((req, res, next) => {
    if (!req.user) {
    return next();
    }
    // JWT NumericDates specified in seconds:
    const currentTime = Math.floor(Date.now() / 1000);
    res.locals({
    paragonToken: jsonwebtoken.sign(
    {
    sub: req.user.id,
    iat: currentTime,
    exp: currentTime + (60 * 60), // 1 hour from now
    },
    process.env.PARAGON_SIGNING_KEY,
    {
    algorithm: "RS256",
    }
    ),
    });
    next();
    });
  2. Use the paragonJwt set in context within the view template, with a call to paragon.authenticate:

    // layout.hbs - Include paragon.authenticate call in the view template
    <body>
    <script type="text/javascript">
    paragon.authenticate("project-id", "{{ paragonToken }}");
    </script>
    </body>

Setup with a managed authentication service

Managed authentication is not currently represented in the options for Signing Keys in your Paragon project settings. You'll need to send us a support message or have been on an onboarding call with us to use a managed authentication service with Paragon.

Since Paragon uses a JSON Web Token (JWT) to encode and validate user identity, many managed services will already have a token that you can pass directly to Paragon.

Firebase Authentication
Auth0
MemberStack
Firebase Authentication

The Firebase ID token can be used directly as the Paragon user token.

You can get a Firebase ID token from the JavaScript client-side library with:

firebase.auth().currentUser.getIdToken(true).then(function(idToken) {
paragon.authenticate("project-id", idToken);
})
Auth0

The Auth0 ID token can be used directly as the Paragon user token.

Auth0 provides comprehensive docs on retrieving the ID token in various contexts. An example of this, using their single page app SDK:

auth0.getIdTokenClaims().then((claims) => {
paragon.authenticate("project-id", claims.__raw);
});
MemberStack

The MemberStack token can be used directly as the Paragon user token.

You can use MemberStack.getToken to retrieve the MemberStack token, as explained in their docs.

MemberStack.onReady(() => {
paragon.authenticate("your project ID", MemberStack.getToken());
});

Just for testing: Generating one-off JWTs

Use the Paragon JWT Generator to generate test JWTs for your development purposes. In production, static tokens should never be used.