
Security News
Socket Integrates With Bun 1.3’s Security Scanner API
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
@dainprotocol/oauth2-storage-drizzle
Advanced tools
Database-agnostic Drizzle ORM storage adapter for OAuth2 Token Manager
Drizzle ORM storage adapter for @dainprotocol/oauth2-token-manager.
npm install @dainprotocol/oauth2-storage-drizzle drizzle-orm
The adapter requires tables to be created before use. You can either:
import { migrate } from '@dainprotocol/oauth2-storage-drizzle';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
const client = postgres(connectionString);
const db = drizzle(client);
// Run migrations to create tables
await migrate(db, { dialect: 'postgres' });
First, create a drizzle.config.ts
file:
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './node_modules/@dainprotocol/oauth2-storage-drizzle/dist/schema',
out: './drizzle',
dialect: 'postgresql', // or 'mysql', 'sqlite'
dbCredentials: {
connectionString: process.env.DATABASE_URL!,
},
});
Then generate and run migrations:
npx drizzle-kit generate:pg
npx drizzle-kit migrate:pg
import { OAuth2Client } from '@dainprotocol/oauth2-token-manager';
import { DrizzleStorageAdapter, migrate } from '@dainprotocol/oauth2-storage-drizzle';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
const client = postgres(connectionString);
const db = drizzle(client);
// Run migrations on first setup (development)
if (process.env.NODE_ENV === 'development') {
await migrate(db, { dialect: 'postgres' });
}
const storage = new DrizzleStorageAdapter(db, {
dialect: 'postgres',
});
const oauth = new OAuth2Client({ storage });
import { DrizzleStorageAdapter, migrate } from '@dainprotocol/oauth2-storage-drizzle';
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);
// Run migrations on first setup (development)
if (process.env.NODE_ENV === 'development') {
await migrate(db, { dialect: 'mysql' });
}
const storage = new DrizzleStorageAdapter(db, {
dialect: 'mysql',
});
import { DrizzleStorageAdapter, migrate } from '@dainprotocol/oauth2-storage-drizzle';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import Database from 'better-sqlite3';
const sqlite = new Database('oauth_tokens.db');
const db = drizzle(sqlite);
// Run migrations on first setup (development)
if (process.env.NODE_ENV === 'development') {
await migrate(db, { dialect: 'sqlite' });
}
const storage = new DrizzleStorageAdapter(db, {
dialect: 'sqlite',
});
The DrizzleStorageAdapter implements all methods from the StorageAdapter interface:
saveToken(input)
- Save or update a token (unique by provider + email)getToken(provider, email)
- Get a specific tokengetTokenById(id)
- Get a token by its IDgetTokensByUserId(userId)
- Get all tokens for a usergetTokensByEmail(email)
- Get all tokens for an emailgetTokensByProvider(provider)
- Get all tokens for a providergetAccounts(userId, provider)
- Get all tokens for a specific user in a specific providergetTokensForEmail(userId, provider, email)
- Get a single token for a specific user, provider, and email (returns null if not found)getTokens(userId, provider)
- Get all tokens for a specific user in a specific provider (alias for getAccounts)updateToken(id, update)
- Update a tokendeleteToken(id)
- Delete a token by IDdeleteTokenByProviderEmail(provider, email)
- Delete a token by provider and emaildeleteExpiredTokens()
- Clean up expired tokenssaveAuthorizationState(state)
- Save an authorization stategetAuthorizationState(state)
- Get an authorization statedeleteAuthorizationState(state)
- Delete an authorization statecleanupExpiredStates()
- Clean up expired states (older than 10 minutes)The adapter automatically creates the following tables:
id
- Unique identifierprovider
- OAuth provider nameuserId
- User identifieremail
- User emailaccessToken
- Encrypted access tokenrefreshToken
- Encrypted refresh token (optional)expiresAt
- Token expiration timestamptokenType
- Token type (e.g., "Bearer")scope
- OAuth scopesmetadata
- Additional metadata (JSON)createdAt
- Creation timestampupdatedAt
- Last update timestampUnique constraint: provider
+ email
state
- Authorization state (primary key)codeVerifier
- PKCE code verifierconfig
- OAuth configuration (JSON)metadata
- Additional metadata (JSON)createdAt
- Creation timestampMIT
FAQs
Database-agnostic Drizzle ORM storage adapter for OAuth2 Token Manager
The npm package @dainprotocol/oauth2-storage-drizzle receives a total of 475 weekly downloads. As such, @dainprotocol/oauth2-storage-drizzle popularity was classified as not popular.
We found that @dainprotocol/oauth2-storage-drizzle demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.
Security News
A data handling bug in OSV.dev caused disputed CVEs to disappear from vulnerability feeds until a recent fix restored over 500 advisories.