Skip to main content

Quick Start

Install the plugin:
pnpm install @corsair-dev/onedrive
Add the OneDrive plugin to your Corsair instance:
corsair.ts
import { createCorsair } from "corsair";
import { onedrive } from "@corsair-dev/onedrive";

export const corsair = createCorsair({
    plugins: [onedrive()],
    database: db,
    kek: process.env.CORSAIR_KEK!,
});

Authentication

Supported Auth Types

  • oauth_2 (default) - OAuth 2.0 (Microsoft)

OAuth Setup

pnpm corsair setup --onedrive client_id=your-client-id client_secret=your-client-secret
pnpm corsair auth --plugin=onedrive
See Get Credentials for step-by-step instructions.

Options

OptionTypeDescription
authType'oauth_2'Authentication method
keystringOAuth token (optional, uses database if not provided)
webhookSecretstringWebhook verification secret (optional)
hooksobjectEndpoint hooks for custom logic
webhookHooksobjectWebhook hooks for event handling
errorHandlersobjectCustom error handlers

Usage

// List files
const files = await corsair.onedrive.api.files.list({});

// Find a file
const file = await corsair.onedrive.api.files.findFile({
    name: "report.docx",
});

// Upload a file
await corsair.onedrive.api.files.upload({
    path: "/Documents/report.txt",
    content: "file content",
});

// Create a folder
await corsair.onedrive.api.files.createFolder({
    name: "New Folder",
    parent_path: "/Documents",
});

// Get drive info
const drive = await corsair.onedrive.api.drive.get({});

// Share an item
await corsair.onedrive.api.permissions.createLink({
    item_id: "item-id",
    type: "view",
    scope: "anonymous",
});

// Access SharePoint
const site = await corsair.onedrive.api.sharepoint.getSite({
    site_id: "site-id",
});

Query cached data

const files = await corsair.onedrive.db.files.search({
    data: {},
    limit: 20,
});

Multi-Tenancy

const tenant = corsair.withTenant("user-123");

const files = await tenant.onedrive.api.files.list({});