SharePoint by @altf1be
Interact with SharePoint document libraries via Microsoft Graph API using certificate-based authentication.
Setup
- 1. Create an Entra app with
Sites.Selected permission and certificate auth - Grant site-level write access via Microsoft Graph PowerShell
- Set environment variables (or create
.env in {baseDir}):
CODEBLOCK0
- 4. Install dependencies: INLINECODE3
Commands
File operations
CODEBLOCK1
Coauthoring (checkout/checkin)
CODEBLOCK2
Supported Office formats
The read command extracts text content from:
- -
.docx → full text extraction via mammoth - INLINECODE6 → sheet names + cell data via exceljs
- INLINECODE7 → slide text extraction via jszip
- INLINECODE8 → text extraction via pdf-parse
- INLINECODE9 /
.md → raw content
Output is plain text suitable for AI processing (summarization, reformatting, action item extraction).
Dependencies
- -
@azure/identity — certificate-based Azure AD authentication - INLINECODE12 — Microsoft Graph API client
- INLINECODE13 — Word document text extraction
- INLINECODE14 — Excel spreadsheet parsing
- INLINECODE15 — PowerPoint XML extraction
- INLINECODE16 — PDF text extraction
- INLINECODE17 — CLI framework
- INLINECODE18 — environment variable loading
Security
- - Certificate auth only (no client secrets, no passwords)
- INLINECODE19 permission (access limited to one SharePoint site)
- Path traversal prevention:
../ is rejected - Delete requires explicit
--confirm flag - No tokens or secrets printed to stdout
- File size limit: configurable max (default 50MB)
Full setup guide
For complete setup from scratch (Entra app, certificate, Sites.Selected, Key Vault):
See the GitHub repository README.
Author
Abdelkrim BOUJRAF — ALT-F1 SRL, Brussels 🇧🇪
X: @altf1be
SharePoint by @altf1be
通过基于证书的身份验证,使用 Microsoft Graph API 与 SharePoint 文档库进行交互。
设置
- 1. 创建一个具有 Sites.Selected 权限和证书认证的 Entra 应用
- 通过 Microsoft Graph PowerShell 授予站点级写入权限
- 设置环境变量(或在 {baseDir} 中创建 .env 文件):
SPTENANTID=your-azure-tenant-id
SPCLIENTID=your-app-client-id
SPCERTPATH=/path/to/certificate.pem
SPSITEID=your-sharepoint-site-id
SPDRIVEID=optional-specific-drive-id
- 4. 安装依赖:cd {baseDir} && npm install
命令
文件操作
bash
显示站点和驱动器信息
node {baseDir}/scripts/sharepoint.mjs info
列出库根目录中的文件
node {baseDir}/scripts/sharepoint.mjs list
列出子文件夹中的文件
node {baseDir}/scripts/sharepoint.mjs list --path Meeting Notes/2026
读取文件内容(从 Office 格式中提取文本)
node {baseDir}/scripts/sharepoint.mjs read --path Report.docx
上传文件
node {baseDir}/scripts/sharepoint.mjs upload --local ./report.docx --remote Reports/Q1-2026.docx
搜索文件
node {baseDir}/scripts/sharepoint.mjs search --query quarterly review
创建文件夹
node {baseDir}/scripts/sharepoint.mjs mkdir --path Meeting Notes/2026
删除(需要 --confirm 标志)
node {baseDir}/scripts/sharepoint.mjs delete --path Drafts/old-file.txt --confirm
协作编辑(签出/签入)
bash
安全编辑:签出 → 上传修改后的文件 → 签入(推荐)
node {baseDir}/scripts/sharepoint.mjs edit --path Report.docx --local ./modified.docx --comment Updated summary
签出文件(锁定以进行独占编辑)
node {baseDir}/scripts/sharepoint.mjs checkout --path Report.docx
签入文件(解锁 + 发布)
node {baseDir}/scripts/sharepoint.mjs checkin --path Report.docx --comment Reviewed and approved
获取在 Office Online 中打开的编辑链接
node {baseDir}/scripts/sharepoint.mjs edit-link --path Report.docx
支持的 Office 格式
read 命令从以下格式中提取文本内容:
- - .docx → 通过 mammoth 提取全文
- .xlsx → 通过 exceljs 提取工作表名称和单元格数据
- .pptx → 通过 jszip 提取幻灯片文本
- .pdf → 通过 pdf-parse 提取文本
- .txt / .md → 原始内容
输出为纯文本,适合 AI 处理(摘要、重新格式化、提取操作项)。
依赖项
- - @azure/identity — 基于证书的 Azure AD 身份验证
- @microsoft/microsoft-graph-client — Microsoft Graph API 客户端
- mammoth — Word 文档文本提取
- exceljs — Excel 电子表格解析
- jszip — PowerPoint XML 提取
- pdf-parse — PDF 文本提取
- commander — CLI 框架
- dotenv — 环境变量加载
安全性
- - 仅证书认证(无客户端密钥,无密码)
- Sites.Selected 权限(访问权限仅限于一个 SharePoint 站点)
- 路径遍历防护:拒绝 ../
- 删除需要显式的 --confirm 标志
- 不会向标准输出打印令牌或密钥
- 文件大小限制:可配置最大值(默认 50MB)
完整设置指南
如需从头开始完整设置(Entra 应用、证书、Sites.Selected、Key Vault):
请参阅 GitHub 仓库 的 README 文件。
作者
Abdelkrim BOUJRAF — ALT-F1 SRL,布鲁塞尔 🇧🇪
X: @altf1be