Authorization

This guide explains how to set up authorization in Plandalf to control who can access your system.

Understanding Authorization with Agents

An agent in Plandalf represents a user who has permission to act on behalf of a customer. The relationship between agents and customers can be:

  • One-to-one: One agent per customer
  • Many-to-many: Multiple agents can work with multiple customers

JWT-Based Authorization

Plandalf uses JSON Web Tokens (JWT) for authorization. Here's what you need to include in your JWT:

FieldRequiredDescription
subYesYour user identifier (string)
customerNoCustomer identifier
grpNoGroup identifier
expNoToken expiration timestamp
emailNoUser email address
audNoSet to "sandbox" for testing with 100% discount

Implementation Guide

Authorization
javascript
// Install the JWT library
npm install jsonwebtoken

// Generate your JWT
import jwt from 'jsonwebtoken';
let token = jwt.sign(claims, "<SECRET>", {algorithm: 'RS256', keyid: '<CLIENT_ID>'});

Example JWT Payload

Here's a complete example of a JWT payload:

json
{
    "sub": "user_abc123",
    "exp": 1721234567,
    "aud": "sandbox",
    "email": "founder@plandalf.com",
    "customer": "cus_NffrFeUfNV2Hib"
}

Next Steps

After generating your JWT:

  1. Pass the token to your frontend
  2. Use the token to initialize the Plandalf SDK