JWT is one of the convenient ways to authenticate users with external apps. AnnounceKit supports JSON Web Tokens for authenticating a user in the widget and on your Portal.
1. Get your secret key
First, you need your workspace's secret key, which signs the user data in the token. Remember, this key is secret: use it only on the server side of your application.
- Open Settings and go to Privacy & Access.
- Find the JWT card.
- Copy the value of JWT secret.
Here is the JWT card, with the secret hidden.
Only a workspace member who can manage settings sees the secret.
2. Generate tokens on your server
Now you can generate a signed token, user_token, which holds the user properties id, name and email. You can also include an optional data object with custom fields (for example { "plan": "pro", "role": "admin" }). These are used for segmentation, just like the data option in the widget config. Make sure the HS256 algorithm is used and included in the JWT Header. You can use any library suitable for your codebase.
3. Authenticate the user
Now that you have the signed user_token, pass it in your widget configuration, or as the user_token query parameter in your Portal's address, for example:https://announcekit.app/acmeco/updates?user_token=eyJhbGciOiJIU6IkpXVCJ9.ey...
In the widget, user_token sits next to the other keys of the widget code:
When a token is sent, AnnounceKit checks it against your JWT secret. A token that does not verify is ignored, and the user is not identified.
Optional: send visitors to your login page
Suppose a visitor who is not signed in tries to open your private Portal. You can send them to your application to sign in, then back to the Portal with a token.
- Open Settings and go to Privacy & Access.
- In Private portal, turn on Private portal, then Require JWT.
- In the JWT card, enter your Login redirect URL.
- Click Save.
Here is the Private portal card with Require JWT turned on.
The Login redirect URL should point to the route of your application that generates the token described in step 2. AnnounceKit adds a redirect_url parameter to it, which holds your Portal's address. After generating the token, combine that redirect_url with the user_token and send the visitor there.