Idiomark OAuth Flow Architecture
Purpose
Idiomark is designed for digital self-sovereignty — users extract THEIR OWN personality data via official OAuth authentication. This is NOT a scraping tool.
Authentication Patterns
1. OAuth 2.0 (Recommended for Self-Sovereignty)
Flow:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Idiomark │ │ Platform │ │ User │
│ (Web UI) │ │ (GitHub, │ │ (Browser) │
│ │ │ Twitter, │ │ │
└──────┬──────┘ │ Reddit...) │ └──────┬──────┘
│ └──────┬──────┘ │
│ │ │
1. Click │ 2. Redirect
"Connect" │ to platform
│ │ login
▼ │
Generate ◄────────────────────────┘
state+nonce
& redirect
to
platform
│
│
3. Store
state
(session)
│
│
4. Redirect
user with:
- client_id
- redirect_uri
- scope
- state
│
▼
┌─────────────────────────────────┐
│ User logs in │
│ & grants permission │
│ to YOUR OWN account │
└────────────┬────────────────┘
│
5. Platform
redirects
back with:
- code
- state
│
▼
┌─────────────────────────────────┐
│ Idiomark receives callback │
│ - Verify state │
│ - Exchange code for token │
│ - Store token securely │
└────────────┬────────────────┘
│
6. Use token
to fetch
AUTHENTICATED
USER'S OWN
DATA
Key Points:
- User grants access to THEIR OWN ACCOUNT
- Token grants access to authenticated user's data only
- Idiomark cannot fetch data from other users
- Scope is explicit (e.g.,
read:org,read:user)
2. Bot Token (Discord, Slack, Telegram)
Pattern:
User creates bot on platform → Gets bot token → Invites bot to THEIR servers
Access:
- Bot can only access servers/channels where it's invited
- Bot cannot access servers without invitation
- Bot sees messages from those servers only
Security:
- Bot token should be server-side secret (never exposed in client code)
- User must invite bot themselves (Idiomark cannot auto-invite)
3. Local File Import (Signal, WhatsApp)
Pattern:
User exports data from platform → Uploads .idiomark/.db file → Parser reads local file
Access:
- Reads locally exported file only
- No API access required
- User provides file explicitly
Security:
- Processing happens client-side only
- No data sent to external server
- File is discarded after parsing
4. Session Cookie/Scraping (TikTok, Behance)
Pattern:
User provides session cookies → Scrapes public profile → Fragile, may violate ToS
Access:
- Public data only (what anyone can see)
- Fragile (cookies expire, platform blocks scrapers)
- May violate platform Terms of Service
Disclaimer:
- Not recommended for serious use
- Use only when no official API exists
- Clearly mark as "scraping" in UI
Implementation Checklist
For Each OAuth Adapter
- Register OAuth app on platform developer portal
- Set redirect URI:
https://your-domain.com/api/oauth/callback/{platform} - Store
client_idandclient_secretin environment variables - Implement state parameter to prevent CSRF
- Store access tokens securely (httpOnly cookies or encrypted DB)
- Refresh token support (if platform provides it)
- Handle token expiration gracefully
- Provide "disconnect" button to revoke access
Security Requirements
- Never store tokens in localStorage (vulnerable to XSS)
- Never expose
client_secretin client-side code - Always use HTTPS for OAuth callbacks
- Always validate state parameter on callback
- Always use PKCE (Proof Key for Code Exchange) for public clients
Platform-Specific OAuth URLs
GitHub
- Auth URL:
https://github.com/login/oauth/authorize - Token URL:
https://github.com/login/oauth/access_token - Scopes:
read:user,read:org,repo(for private repos) - Docs: https://docs.github.com/en/apps/oauth-apps
Twitter/X
- Auth URL:
https://twitter.com/i/oauth2/authorize - Token URL:
https://api.twitter.com/2/oauth2/token - Scopes:
tweet.read,users.read,like.read - Docs: https://developer.twitter.com/en/docs/authentication/oauth-2-0
Reddit
- Auth URL:
https://www.reddit.com/api/v1/authorize - Token URL:
https://www.reddit.com/api/v1/access_token - Scopes:
read,identity,history,subscribe - Docs: https://github.com/reddit-archive/reddit/wiki/OAuth2
Discord
- Auth URL:
https://discord.com/oauth2/authorize - Token URL:
https://discord.com/api/oauth2/token - Scopes: Bot-specific (
identify,guilds,messages.read) - Docs: https://discord.com/developers/docs/topics/oauth2
Example: Callback Handler (Next.js App Router)
// app/api/oauth/callback/[platform]/route.ts
import { NextRequest, NextResponse } from 'next/server'
export async function GET(
request: NextRequest,
{ params }: { params: { platform: string } }
) {
const searchParams = request.nextUrl.searchParams
const code = searchParams.get('code')
const state = searchParams.get('state')
const error = searchParams.get('error')
// Handle errors
if (error) {
return NextResponse.redirect(
`/extract?error=${encodeURIComponent(error)}`
)
}
// Verify state (CSRF protection)
const savedState = await getStoredState(state)
if (!savedState) {
return NextResponse.redirect('/extract?error=invalid_state')
}
// Exchange code for token
const token = await exchangeCodeForToken(params.platform, code)
// Store token securely (httpOnly cookie)
const response = NextResponse.redirect('/extract')
response.cookies.set(`idiomark_${params.platform}_token`, token, {
httpOnly: true,
secure: true,
sameSite: 'lax',
maxAge: 60 * 60 * 24 * 30, // 30 days
path: '/'
})
return response
}
Token Storage Strategy
Recommended: Server-Side Session
┌─────────────────────────────────────┐
│ OAuth Callback │
│ - Exchange code for token │
│ - Create encrypted session │
│ - Return httpOnly cookie │
└──────────────┬──────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Subsequent API Requests │
│ - Cookie sent automatically │
│ - Server decrypts session │
│ - Server makes API call │
│ - Returns data to client │
└─────────────────────────────────────┘
Not Recommended: Client-Side Storage
❌ localStorage - Vulnerable to XSS
❌ sessionStorage - Vulnerable to XSS
❌ URL params - Logged in access logs
Privacy & Ethics Statement
Idiomark is designed for:
- ✅ Users extracting THEIR OWN digital footprint
- ✅ Creating portable personality profiles
- ✅ Self-sovereignty over personal data
Idiomark is NOT designed for:
- ❌ Scraping others' public data
- ❌ Surveillance or background checks
- ❌ Accessing private data without consent
- ❌ Competitive intelligence
Users must:
- Only extract data from accounts they own
- Have explicit permission for data they access
- Respect platform Terms of Service
- Comply with data protection laws (GDPR, CCPA)
Last Updated: 2025-02-12