Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@dainprotocol/oauth2-storage-drizzle

Package Overview
Dependencies
Maintainers
12
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dainprotocol/oauth2-storage-drizzle

Database-agnostic Drizzle ORM storage adapter for OAuth2 Token Manager

npmnpm
Version
0.1.0
Version published
Weekly downloads
149
254.76%
Maintainers
12
Weekly downloads
 
Created
Source

@dainprotocol/oauth2-storage-drizzle

Drizzle ORM storage adapter for @dainprotocol/oauth2-token-manager.

Installation

npm install @dainprotocol/oauth2-storage-drizzle drizzle-orm

Usage

PostgreSQL

import { OAuth2Client } from '@dainprotocol/oauth2-token-manager';
import { DrizzleStorageAdapter } from '@dainprotocol/oauth2-storage-drizzle';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

const client = postgres(connectionString);
const db = drizzle(client);

const storage = new DrizzleStorageAdapter(db, {
  dialect: 'postgres',
});

const oauth = new OAuth2Client({ storage });

MySQL

import { drizzle } from 'drizzle-orm/mysql2';
import mysql from 'mysql2/promise';

const connection = await mysql.createConnection({
  host: 'localhost',
  user: 'root',
  database: 'oauth_tokens',
});

const db = drizzle(connection);

const storage = new DrizzleStorageAdapter(db, {
  dialect: 'mysql',
});

SQLite

import { drizzle } from 'drizzle-orm/better-sqlite3';
import Database from 'better-sqlite3';

const sqlite = new Database('oauth_tokens.db');
const db = drizzle(sqlite);

const storage = new DrizzleStorageAdapter(db, {
  dialect: 'sqlite',
});

Schema

The adapter automatically creates the following tables:

oauth2_tokens

  • id - Unique identifier
  • provider - OAuth provider name
  • userId - User identifier
  • email - User email
  • accessToken - Encrypted access token
  • refreshToken - Encrypted refresh token (optional)
  • expiresAt - Token expiration timestamp
  • tokenType - Token type (e.g., "Bearer")
  • scope - OAuth scopes
  • metadata - Additional metadata (JSON)
  • createdAt - Creation timestamp
  • updatedAt - Last update timestamp

Unique constraint: provider + email

oauth2_authorization_states

  • state - Authorization state (primary key)
  • codeVerifier - PKCE code verifier
  • config - OAuth configuration (JSON)
  • metadata - Additional metadata (JSON)
  • createdAt - Creation timestamp

Features

  • Multi-database support (PostgreSQL, MySQL, SQLite)
  • Automatic schema creation
  • Secure token encryption
  • Built-in cleanup for expired tokens and states
  • TypeScript support

License

MIT

Keywords

oauth2

FAQs

Package last updated on 02 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts