const express = require("express");
const { jwtVerify } = require("@kinde-oss/kinde-node-express");
const jwt = require("jsonwebtoken");
require("dotenv").config();
const app = express();
app.use(express.json());
// Environment variables from your .env file:
const KINDES_SUBDOMAIN = process.env.KINDES_SUBDOMAIN; // e.g., "your_kinde_subdomain"
const SHARED_SECRET = process.env.SHARED_SECRET; // Your HS256 secret for signing tokens
const KINDES_ISSUER = `https://${KINDES_SUBDOMAIN}.kinde.com`;
console.log("Server configuration:", {
kindeSubdomain: KINDES_SUBDOMAIN,
kindeIssuer: KINDES_ISSUER,
sharedSecretExists: !!SHARED_SECRET,
});
// Initialize the Kinde verifier middleware. This caches Kinde's JWKS.
const verifier = jwtVerify(KINDES_ISSUER);
// Token exchange endpoint: verifies the incoming Kinde token then issues a new token.
app.post("/exchange-token", verifier, (req, res) => {
console.log("Token exchange request received");
const express = require("express");
const { jwtVerify } = require("@kinde-oss/kinde-node-express");
const jwt = require("jsonwebtoken");
require("dotenv").config();
const app = express();
app.use(express.json());
// Environment variables from your .env file:
const KINDES_SUBDOMAIN = process.env.KINDES_SUBDOMAIN; // e.g., "your_kinde_subdomain"
const SHARED_SECRET = process.env.SHARED_SECRET; // Your HS256 secret for signing tokens
const KINDES_ISSUER = `https://${KINDES_SUBDOMAIN}.kinde.com`;
console.log("Server configuration:", {
kindeSubdomain: KINDES_SUBDOMAIN,
kindeIssuer: KINDES_ISSUER,
sharedSecretExists: !!SHARED_SECRET,
});
// Initialize the Kinde verifier middleware. This caches Kinde's JWKS.
const verifier = jwtVerify(KINDES_ISSUER);
// Token exchange endpoint: verifies the incoming Kinde token then issues a new token.
app.post("/exchange-token", verifier, (req, res) => {
console.log("Token exchange request received");