This is a sample Node.js application demonstrating how to implement custom backend authentication with HelpKit's protected access feature. The demo uses JWT (JSON Web Tokens) for authentication.
HelpKit is a modern documentation and help center platform that helps teams create beautiful, searchable knowledge bases. It offers protected access features that allow you to restrict content to authenticated users only. With its powerful customization options and developer-friendly approach, HelpKit makes it easy to create and maintain documentation that your users will love. Visit helpkit.so to learn more about how HelpKit can transform your documentation experience.
HelpKit's protected access feature allows you to restrict access to your knowledge base to authenticated users only. This demo shows how to:
- Implement a custom login page
- Authenticate users against your own backend
- Generate a JWT token after successful authentication
- Redirect users back to HelpKit with the token
- Allow HelpKit to validate the token and grant access
┌──────────┐ ┌─────────────┐ ┌──────────┐
│ User │ │ Your Auth │ │ HelpKit │
│ Browser │ │ Server │ │ Site │
└────┬─────┘ └──────┬──────┘ └────┬─────┘
│ │ │
│ 1. Visit HelpKit Site │ │
│ ─────────────────────────────────────────────────────────>│
│ │ │
│ 2. Redirect to Login │ │
│ <─────────────────────────────────────────────────────────│
│ │ │
│ 3. Visit Auth Server │ │
│ ─────────────────────────────>│ │
│ │ │
│ 4. Show Login Form │ │
│ <─────────────────────────────│ │
│ │ │
│ 5. Submit Credentials │ │
│ ─────────────────────────────>│ │
│ │ │
│ 6. Validate Credentials │ │
│ ┌───────────┘ │
│ │ │
│ │ 7. Generate JWT │
│ └───────────┐ │
│ │ │
│ 8. Redirect with JWT Token │ │
│ <─────────────────────────────────────────────────────────│
│ │ │
│ 9. Access with JWT Token │ │
│ ─────────────────────────────────────────────────────────>│
│ │ │
│ │ 10. Verify JWT │
│ │ Token │
│ │ ┌─────────────┐ │
│ │ │ │ │
│ │ └─────────────┘ │
│ │ │
│ 11. Grant Access │ │
│ <─────────────────────────────────────────────────────────│
│ │ │
- Node.js (v14 or newer)
- npm or yarn
- A HelpKit site with protected access enabled
- A visitor secret signing key from HelpKit
-
Clone this repository:
git clone https://github.com/helpkit/custom-backend-auth-demo.git cd custom-backend-auth-demo -
Install dependencies:
npm install -
Create a
.envfile in the root directory with the following variables:HELPKIT_VISITOR_SECRET_KEY=your_visitor_signing_key HELPKIT_SITE_URL=https://your-project-name.helpkit.so/access (Use custom domain if you have one) PORT=9000Note: Make sure to append
/accessto your HelpKit site URL. -
Start the server:
npm start -
Visit
http://localhost:4000/loginto see the login form.
- Users visit your custom login page (
/login) - After successful authentication, your backend:
- Generates a JWT token signed with your HelpKit visitor signing key
- Redirects users to your HelpKit site with the token (
https://your-project-name.helpkit.so/access?jwt_token=...)
- HelpKit validates the token and grants access if valid
For demo purposes, this application has hardcoded credentials:
- Username:
user - Password:
demo
In a production environment, you would authenticate against your user database.
- In your HelpKit project settings, enable "Custom Backend Authentication"
- Set your "Sign-in URL" to point to your login endpoint (e.g.,
https://your-auth-server.com/login) - Copy the generated visitor signing key to your
.envfile
You can customize the login page by modifying the views/login.ejs template.
- Always use HTTPS in production
- Store your visitor signing key securely
- Set appropriate expiration times for your JWT tokens
- Implement proper user authentication logic
MIT