Data Adapter
セッション情報の保存方法を定義したもの。
const rp = await OidcClient.factory({ //... dataAdapter: OIDCClientDataAdapter, //...})
- 本パッケージにはSQLite/LokiJS/Lowdb/Redisを使用したデータアダプターが含まれる
- カスタムデータアダプターを作成可能
- 既定ではSQLiteのインメモリーモードが使用される
- 複数のOPを使用する場合は一つのデータアダプターを共有する
- 参照: OIDCClientDataAdapter
SQLite
Bun内蔵のSQLiteドライバーを使用する。
import { SQLiteAdapter } from 'elysia-openid-client/dataAdapters/SQLiteAdapter';
// インメモリーモードconst memoryAdapter = new SQLiteAdapter();// new SQLiteAdapter({ filename: ":memory:" }) と同義
// 永続化モードconst fileAdapter = new SQLiteAdapter({ filename: "path/to/sessions.sqlite"});
LokiJS
LokiJSを使用する。
bun add lokijsbun add -D @types/lokijs
// インメモリーモードimport { LokiInMemoryAdapter } from 'elysia-openid-client/dataAdapters/LokiInMemoryAdapter';const memoryAdapter = new LokiInMemoryAdapter();
// 永続化モードimport { LokiFileAdapter } from 'elysia-openid-client/dataAdapters/LokiFileAdapter';const fileAdapter = await LokiFileAdapter.factory({ filename: "path/to/sessions.db"});
Lowdb
Lowdbを使用する。
bun add lowdb
import { LowdbAdapter } from 'elysia-openid-client/dataAdapters/LowdbAdapter';
// インメモリーモードconst memoryAdapter = await LowdbAdapter.factory();
// 永続化モードconst fileAdapter = await LowdbAdapter.factory({ filename: "sessions.json",})
Redis
bun add ioredis
import { RedisAdapter } from 'elysia-openid-client/dataAdapters/RedisAdapter';const redisAdapter = new RedisAdapter({ port: 6379, host: "localhost",});
カスタムデータアダプター
import type { OIDCClientDataAdapter } from 'elysia-openid-client';export class MyDataAdapter implements OIDCClientDataAdapter { // ...}
// app.tsimport { MyDataAdapter } from 'path/to/MyDataAdapter';const rp = await OidcClient.factory({ //... dataAdapter: new MyDataAdapter(), //...})