Skip to content

About

Microsoft 365 E5 developer subscription auto-renewal on Cloudflare Workers: scheduled Graph API calls with KV token storage and Telegram notifications

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

AutoApi E5 - Cloudflare Worker Edition

CI codecov

E5 auto-renewal application ported to Cloudflare Workers platform.

Features

  • ✅ Generate Excel files in memory using SheetJS (xlsx)
  • ✅ Store tokens using KV Storage (replaces .env file)
  • ✅ Support for Cron Triggers for scheduled execution
  • ✅ All API functionalities fully ported

Installation

1. Install Dependencies

npm install

2. Setup KV Namespace

# Create KV namespace
wrangler kv namespace create "E5_CONFIG"

# Update the returned ID in `wrangler.jsonc` under `kv_namespaces[0].id`

3. Set Secrets (recommended)

Use Cloudflare Secrets instead of plain env vars:

wrangler secret put CLIENT_ID            # Azure Application ID
wrangler secret put CLIENT_SECRET        # Azure Application Secret
wrangler secret put ADMIN_TOKEN          # required to call the trigger endpoints
wrangler secret put TELEGRAM_BOT_TOKEN   # optional
wrangler secret put CHAT_ID              # optional
wrangler secret put TOPIC_ID             # optional, forum topic (message_thread_id) in a supergroup

Notes:

  • Secrets are referenced in code via c.env.VAR_NAME (e.g. c.env.CLIENT_ID).
  • For local development, you can use wrangler secret put in dev too, or a .dev.vars file (not committed) for convenience.

4. Initialize Token

# Write initial refresh_token to KV
wrangler kv key put --namespace-id=YOUR_NAMESPACE_ID "MS_TOKEN" "YOUR_REFRESH_TOKEN" --remote

5. Deploy

npm run deploy

Test Endpoints

After deployment, manually trigger via these endpoints. The POST endpoints require Authorization: Bearer <ADMIN_TOKEN> and return 401 if ADMIN_TOKEN is not set:

  • POST /update-token - Update token
  • POST /run-read - Execute read APIs
  • POST /run-write - Execute write APIs
  • GET /status - Check whether tokens are present in KV
curl -X POST -H "Authorization: Bearer $ADMIN_TOKEN" https://<your-worker>.workers.dev/run-read

Cron Schedule

Configured schedule (UTC time):

  • Token update: Monday, Thursday, Saturday at 10:10
  • Read APIs: Every 6 hours on weekdays
  • Write APIs: Daily at 23:12

Technical Differences

Original (Python + Docker)

  • Uses xlsxwriter to generate Excel
  • Stores token in .env file
  • Uses crontab for scheduling

Worker Edition (TypeScript)

  • Uses SheetJS (xlsx)
  • Stores token in KV Storage
  • Uses Cron Triggers

Limitations

  • Workers have 30-second execution time limit
  • Cannot use time.sleep() delays
  • All file operations performed in memory

Monitoring

View logs using Wrangler:

npm run tail

License

MIT

About

Microsoft 365 E5 developer subscription auto-renewal on Cloudflare Workers: scheduled Graph API calls with KV token storage and Telegram notifications

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages