import Elysia from "elysia";
import { OidcClient } from "elysia-openid-client";
import { SQLiteAdapter } from "elysia-openid-client/dataAdapters/SQLiteAdapter";
const baseUrl = "https://app.example.com";
// Use the same data adapter for all issuers
const dataAdapter = new SQLiteAdapter();
// Callback URL: `https://app.example.com/auth/callback`
const rp1 = await OidcClient.factory({
issuerUrl: "https://issuer.exmaple.com",
client_secret: "client-secret",
loginRedirectUrl: "/select",
const endpoints1 = rp1.endpoints;
console.log(rp1.issuer.metadata);
// Callback URL: `https://app.example.com/another/callback`
const rp2 = await OidcClient.factory({
issuerUrl: "https://another-issuer.exmaple.com",
client_id: "another-client-id",
client_secret: "another-client-secret",
const endpoints2 = rp2.endpoints;
console.log(rp2.issuer.metadata);
// Use one of the RP as the main RP
// In this case, RP1 is the main RP
// Register additional RP client to main RP instance to handle all clients in main RP auth hook
rp1.registerClient(rp2.client);
console.log(Object.keys(rp1.clients));
// Use the main RP auth hook
const authHook = rp1.authHook;
.get("/", ({ sessionStatus }) =>
sessionStatus ? "Logged in" : "Restricted",
.get("/status", ({ sessionStatus }) => sessionStatus)
// Issuer can be identified from `sessionClaims.iss`
.get("/claims", ({ sessionClaims }) => sessionClaims)
// Get UserInfo internally
async ({ cookie, session }) =>
// Use the main PR instance
await rp1.userinfo({ cookie, session }),
.get("/select", ({ set }) => {
set.headers["Content-Type"] = "text/html";
<p><a href="/auth/login">Issuer</a></p>
<p><a href="/another/login">Another</a></p>
.get("/free", () => "Not restricted")
.get("/logout", () => "Logout completed")