Skip to content
Skillv1.0.0

notion-enterprise-rbac

Configure Notion enterprise access control with OAuth, workspace permissions, and audit logging. Use when implementing OAuth public integrations, managing multi-workspace access, or building permissio

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (plugins/saas-packs/notion-pack/skills/notion-enterprise-rbac/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill notion-enterprise-rbac. Copyright stays with the author (MIT).

Notion Enterprise RBAC

Overview

Implement enterprise-grade access control for Notion integrations. This covers the full OAuth 2.0 authorization flow for public integrations (multi-tenant), per-workspace token storage with encryption at rest, Notion's page-level permission model and how to handle ObjectNotFound vs RestrictedResource, an application-level role system (admin/editor/viewer) layered on top of Notion's permissions, comprehensive audit logging to a Notion database, and workspace deauthorization cleanup.

Prerequisites

  • Notion public integration created at https://www.notion.so/my-integrations (for OAuth)
  • @notionhq/client v2+ installed (npm install @notionhq/client)
  • Python alternative: notion-client (pip install notion-client)
  • Database for storing per-workspace tokens (PostgreSQL, DynamoDB, etc.)
  • HTTPS endpoint for OAuth callback (required by Notion)

Instructions

The workflow has three steps. Each is summarized here with its key entry point; the complete, copy-ready code for all three lives in the full implementation reference.

Step 1: OAuth 2.0 Authorization Flow

Notion uses OAuth 2.0 for public integrations to reach external workspaces. Build an authorization URL with a random state for CSRF protection, redirect the user, then on callback verify the state and exchange the code for a workspace access token. Notion's token endpoint uses HTTP Basic auth with your client id and secret:

function getAuthorizationUrl(state: string): string {
  const params = new URLSearchParams({
    client_id: process.env.NOTION_OAUTH_CLIENT_ID!,
    response_type: 'code',
    owner: 'user',       // 'user' = user-level token, 'workspace' = workspace-level
    redirect_uri: process.env.NOTION_REDIRECT_URI!,
    state,               // CSRF protection — must verify on callback
  });
  return `https://api.notion.com/v1/oauth/authorize?${params}`;
}

The token exchange returns access_token, bot_id (the primary key per installation), workspace_id, and owner metadata. A Python equivalent and the full Express callback handler are in the implementation reference.

Step 2: Token Storage and Permission-Aware API Calls

Store one token per bot_id (encrypt access_token at rest — use KMS or column-level encryption in production), and construct a per-workspace Client on demand. Wrap every page read so Notion's permission model is handled explicitly rather than crashing:

// ObjectNotFound = page exists but is NOT shared with the integration
// (NOT the same as deleted); RestrictedResource = missing capability;
// Unauthorized = token revoked. See the reference for the full switch.
async function safePageAccess(notion: Client, pageId: string) { /* ... */ }

The full TokenStore class, the complete safePageAccess switch, and a discoverAccessiblePages search-pagination helper are in the implementation reference.

Step 3: Application-Level Roles and Audit Logging

Layer an application role system (admin/editor/viewer) on top of Notion's permissions via a ROLE_PERMISSIONS table and a requirePermission Express middleware, and record every authorization decision through an auditLog function that writes structured logs and optionally a Notion audit database. Audit writes must never crash the app (wrap in try/catch), and workspace deauthorization should log then revoke the stored token. The complete role table, middleware, route examples, auditLog, and handleDeauthorization are in the implementation reference.

Output

  • Complete OAuth 2.0 flow for multi-workspace access (TypeScript + Python)
  • Per-workspace token storage with encryption guidance
  • Permission-aware API calls handling ObjectNotFound vs RestrictedResource
  • Content discovery via search endpoint
  • Application-level role system (admin/editor/viewer) with Express middleware
  • Comprehensive audit logging to structured logs and optionally to Notion database
  • Workspace deauthorization cleanup handler

Error Handling

Issue Cause Solution
OAuth callback fails Redirect URI mismatch Must match exactly in integration settings (including trailing slash)
invalid_grant on token exchange Code expired or already used Authorization codes are single-use; restart OAuth flow
ObjectNotFound on page access Page not shared with integration User must share via "..." menu > Connections
RestrictedResource Integration missing capability Edit capabilities at notion.so/my-integrations
Unauthorized (401) Token revoked by user Prompt re-authorization; clean up stored token
State mismatch on callback CSRF attack or session expired Reject the callback; redirect to start OAuth again

Examples

A complete Express integration that wires the OAuth start and callback routes, persists the workspace token, records a workspace_authorized audit entry, and exposes a /workspaces listing endpoint is provided in the worked examples reference. It composes the getAuthorizationUrl, exchangeCodeForToken, tokenStore, and auditLog building blocks from the three Instructions steps into a runnable end-to-end flow.

Resources

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-notion-enterp-52cbf7/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-notion-enterp-52cbf7.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-notion-enterp-52cbf7",
  "kind": "skill",
  "name": "notion-enterprise-rbac",
  "description": "Configure Notion enterprise access control with OAuth, workspace permissions, and audit logging. Use when implementing OAuth public integrations, managing multi-workspace access, or building permission-aware Notion applications. Trigger with phrases like \"notion SSO\", \"notion RBAC\", \"notion enterprise\", \"notion OAuth\", \"notion permissions\", \"notion multi-workspace\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "saas",
      "productivity",
      "notion",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Configure Notion enterprise access control with OAuth, workspace permissions, and audit logging. Use when implementing OAuth public integrations, managing multi-workspace access, or building permission-aware Notion applications. Trigger with phrases like \"notion SSO\", \"notion RBAC\", \"notion enterprise\", \"notion OAuth\", \"notion permissions\", \"notion multi-workspace\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "plugins/saas-packs/notion-pack/skills/notion-enterprise-rbac/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/plugins/saas-packs/notion-pack/skills/notion-enterprise-rbac/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/plugins/saas-packs/notion-pack/skills/notion-enterprise-rbac/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Read,",
      "Write,",
      "Edit"
    ],
    "license": "MIT"
  },
  "instructions": "# Notion Enterprise RBAC\n\n## Overview\n\nImplement enterprise-grade access control for Notion integrations. This covers the full OAuth 2.0 authorization flow for public integrations (multi-tenant), per-workspace token storage with encryption at rest, Notion's page-level permission model and how to handle `ObjectNotFound` vs `RestrictedResource`, an application-level role system (admin/editor/viewer) layered on top of Notion's permissions, comprehensive audit logging to a Notion database, and workspace deauthorization cleanup.\n\n## Prerequisites\n\n- Notion public integration created at <https://www",
  "cost": {
    "context_tokens": 1567
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-notion-enterp-52cbf7/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.