Skip to main content

Recognize your signed-in users with Harvestr Identity

Let the users already signed in to your product send feedback on the widget and use your Portal without entering their email.

Written by Marina Salmon

Your users are already signed in to your product. With Harvestr Identity, the feedback widget and your Portal recognize them too: no email to type, no code to copy from their inbox. Their feedback, upvotes and comments are tied to the right person from the first click.

It works like this: your server signs a short-lived token for the signed-in user with a private key, and Harvestr checks it with the matching public key. Harvestr never sees your private key.

Prerequisites

  • a Harvestr Elite subscription

  • an Editor account to manage the keys

  • a developer who can add a small endpoint to your server: the token must be signed on your server, never in the browser

1. Add a key

Go to Settings > Harvestr Identity and click Add key. You have two options:

  • Managed key: Harvestr generates the key pair and your browser downloads the private key, a .pem file. Store it safely right away: Harvestr doesn't keep it, and once the dialog is closed it can never be downloaded again. If you lose it, delete the key and add a new one.

  • Import key: you generate the pair yourself and paste only its public key, in PEM format. Harvestr accepts EC P-256 keys (ES256) and RSA keys of 2048 bits or more (RS256). The dialog shows the openssl commands to generate one.

Each key has a key ID (kid), shown when you click Show details on its row. Your server writes it in every token it signs, so Harvestr knows which key to check the token with.

Never paste a private key in Harvestr. If you do by mistake, Harvestr refuses it: consider that pair leaked and generate a new one.

2. Sign a token on your server

Each time a signed-in user needs to be recognized, your server signs a JWT with the private key. The settings page shows a ready-to-adapt example in Node.js:

const token = jwt.sign(    { email: user.email, name: user.name },    privateKey,    {        algorithm: "RS256",        keyid: "YOUR_KEY_ID",        audience: "harvestr-identify",        expiresIn: "5m",        jwtid: crypto.randomUUID()    });

What Harvestr checks:

  • email: required, the user's email

  • name: optional, used when Harvestr creates the user

  • audience: always harvestr-identify

  • lifetime: 5 minutes at most between the issue and expiry dates

  • token ID (jwtid): unique, as each token can be used only once

  • key ID (kid header): one of your active keys, with the algorithm of that key (RS256 for a managed key)

Harvestr trusts the email in a valid token without asking the user to confirm it. Only sign tokens for users your product has signed in, with an email you know is theirs.

3. Recognize users on the feedback widget

This works with the SDK install method of the widget. In Settings > Integrations > Feedback widget, pick SDK in the Install card: a second snippet appears under the install snippet. Click Copy code and add it to your pages, after the install snippet.

That snippet asks your server for a token at the address /harvestr-identity-token, which you create:

  • when a user is signed in, it answers a freshly signed token, as plain text

  • when nobody is signed in, it answers an empty response, or a 401 or 403 status

You can serve it at another address: change the URL in the snippet. When your user signs out of your product, call window.HFC("logout") so the widget forgets them too.

The widget then shows Signed in as with the user's name or email, and skips the email step. It asks your server for a new token on its own when its session is about to expire.

The snippet runs when the widget starts with a launcher. If you only open the widget from your own code with window.HFC("open"), call identifyHarvestrUser() yourself before opening it.

4. Recognize users on your Portal

Visitors of your Portal can be signed in from a link in your product. Add a signed token to the Portal address, after #harvestr_identify=:

https://portal.harvestr.io/YOUR_PORTAL_ID#harvestr_identify=SIGNED_TOKEN

The simplest setup is a Roadmap link in your product that points to a route of your server: it signs a token for the signed-in user, then redirects to that address. Harvestr signs the visitor in, then removes the token from the address bar.

If the token is missing or refused, the Portal opens as usual and nobody is signed in. Visitors who arrive without a token can still sign in with the code sent to their email.

How long users stay signed in

A recognized user stays signed in for up to 24 hours. On the widget, a new token is requested automatically. On the Portal, opening it again from your link signs them back in.

Rotate or remove a key

You can keep several keys: all active keys are accepted. To replace a key without interruption, add the new one, switch your server to it, then retire the old one from its ⋯ menu:

  • Revoke at a date: the key keeps working until that day, then tokens signed with it are refused. Users already recognized stay signed in until their session ends. You can change or cancel the date until it passes.

  • Delete key: tokens signed with it are refused right away, and every user recognized through it is signed out. A deleted key can never be added again.

To check that a key in Harvestr matches the one on your server, open its details: Copy command gives you an openssl command that prints the same fingerprint from your key file.

Troubleshooting

Users still have to enter their email

Check, in this order:

  • the token is signed with an active key, and its kid matches that key's ID

  • the audience is harvestr-identify

  • the token lasts 5 minutes or less, and your server's clock is on time

  • each token is new: a token already used is refused

  • for the widget, the install method is SDK and your token endpoint answers the token as plain text

Still stuck? Reach out to our support team with an example token's header and claims (never your private key).

Related

Did this answer your question?