Support IDE integrations (GitHub Copilot, Cursor, Windsurf) that use OAuth device flows instead of API keys.
User App → InferShield Proxy (with API key) → OpenAI API
↓
Threat Detection
Limitation: Requires API key in environment. Doesn't work with OAuth-based tools.
IDE (Cursor/Copilot) → InferShield OAuth Proxy → GitHub/OpenAI OAuth → LLM
↓
Threat Detection + Token Management
User initiates:
infershield auth loginInferShield:
- Generates device code + user code
- Displays to user:
Visit: https://github.com/login/device Code: XXXX-YYYY - Polls OAuth provider for token
User:
- Opens browser
- Enters code
- Authorizes InferShield
InferShield receives:
- Access token
- Refresh token
- Token expiry
Store tokens securely (encrypted at rest):
{
"user_id": "alex@example.com",
"provider": "openai",
"access_token": "encrypted_xxx",
"refresh_token": "encrypted_yyy",
"expires_at": 1708542000,
"created_at": 1708538400
}Storage options:
- v0.2 (single-user): Encrypted JSON file
- v0.3 (multi-user): SQLite + encryption
- Enterprise: PostgreSQL + Vault integration
IDE makes request:
POST http://localhost:8000/v1/chat/completions
Authorization: Bearer <infershield_token>
InferShield:
- Validates InferShield token
- Looks up stored OAuth tokens
- Refreshes if expired
- Runs threat detection on request
- Forwards to LLM with OAuth token
- Logs request + response
Auto-refresh logic:
async function getValidToken(userId, provider) {
const stored = await tokenStore.get(userId, provider);
if (Date.now() < stored.expires_at - 300000) {
// Token valid for >5 min
return stored.access_token;
}
// Token expired or expiring soon - refresh
const refreshed = await oauthProvider.refresh(stored.refresh_token);
await tokenStore.update(userId, provider, {
access_token: refreshed.access_token,
refresh_token: refreshed.refresh_token,
expires_at: Date.now() + refreshed.expires_in * 1000
});
return refreshed.access_token;
}Scope: One developer, one machine
Components:
- CLI:
infershield auth login/logout/status - Token storage: Encrypted JSON (~/.infershield/tokens.json)
- OAuth client: GitHub, OpenAI device flow
- Proxy updates: Accept InferShield auth tokens
Files to create:
proxy/
├── auth/
│ ├── device-flow.js # OAuth device flow logic
│ ├── token-store.js # Encrypted token storage
│ └── token-refresh.js # Auto-refresh logic
├── cli/
│ └── auth-cli.js # CLI commands
└── middleware/
└── oauth-auth.js # Request authentication
Example usage:
# Authenticate once
$ infershield auth login openai
Visit: https://github.com/login/device
Code: ABCD-1234
✓ Authenticated as alex@example.com
# IDE connects via InferShield
$ export OPENAI_BASE_URL=http://localhost:8000/v1
$ cursor # Uses InferShield automaticallyScope: Team deployments, multiple developers
New components: 4. User management: CLI user creation 5. Token isolation: Per-user token storage 6. Admin CLI: User list, revoke, audit
Database schema:
CREATE TABLE users (
id TEXT PRIMARY KEY,
email TEXT UNIQUE,
created_at INTEGER
);
CREATE TABLE oauth_tokens (
user_id TEXT,
provider TEXT,
access_token_encrypted BLOB,
refresh_token_encrypted BLOB,
expires_at INTEGER,
PRIMARY KEY (user_id, provider),
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE audit_log (
id TEXT PRIMARY KEY,
user_id TEXT,
request_id TEXT,
timestamp INTEGER,
risk_score INTEGER,
blocked BOOLEAN
);Scope: Large organizations, SSO, compliance
New components: 7. SSO integration: SAML, Okta, Azure AD 8. Centralized token management: Admin dashboard 9. Per-user compliance reporting: Audit exports 10. Team policies: Different rules per team
Authorization endpoint:
POST https://api.openai.com/v1/oauth/device/code
Token endpoint:
POST https://api.openai.com/v1/oauth/token
Scopes needed:
api.readapi.write
Authorization endpoint:
POST https://github.com/login/device/code
Token endpoint:
POST https://github.com/login/oauth/access_token
API endpoint:
https://api.githubcopilot.com/
Status: Not publicly available yet (API keys only)
Fallback: Support API key mode for Anthropic until OAuth available
Encryption key derivation:
const encryption_key = pbkdf2(
password: process.env.INFERSHIELD_MASTER_KEY,
salt: user_id,
iterations: 100000,
keylen: 32,
digest: 'sha256'
);Encryption algorithm:
- AES-256-GCM
- Random IV per token
- Store:
{iv, authTag, ciphertext}
User-initiated:
$ infershield auth logout openai
✓ Token revoked. Re-authenticate to continue.Admin-initiated (multi-user):
$ infershield admin revoke alex@example.com openai
✓ Revoked OpenAI token for alex@example.comAutomatic:
- On OAuth refresh failure (token invalidated)
- On repeated auth errors (compromised token)
Log every token use:
{
"timestamp": 1708538400,
"user_id": "alex@example.com",
"provider": "openai",
"action": "chat.completion",
"risk_score": 15,
"blocked": false,
"request_id": "req_abc123"
}- Device flow simulation: Mock OAuth responses
- Token encryption/decryption: Verify no data loss
- Token refresh logic: Test expiry handling
- Error handling: Invalid tokens, network failures
- End-to-end flow: CLI login → IDE request → LLM response
- Token persistence: Restart proxy, tokens still valid
- Multi-user isolation: User A can't access User B's tokens
- Threat detection: OAuth requests still get scanned
- GitHub Copilot: Authenticate, use Copilot in VS Code
- Cursor: Authenticate, use Cursor AI features
- Token expiry: Wait for token expiry, verify auto-refresh
- Revocation: Logout, verify requests fail
# 1. Update InferShield
git pull origin main
# 2. Install CLI
npm install -g @infershield/cli
# 3. Authenticate
infershield auth login openai
# Follow browser prompts
# 4. Start proxy
docker run -p 8000:8000 \
-v ~/.infershield:/root/.infershield \
infershield/proxy:v0.2
# 5. Configure IDE
export OPENAI_BASE_URL=http://localhost:8000/v1
# 6. Use normally
cursor # All requests secured automatically# 1. Start proxy (team mode)
docker run -p 8000:8000 \
-e INFERSHIELD_MODE=multi-user \
-e INFERSHIELD_MASTER_KEY=<secret> \
-v /opt/infershield:/data \
infershield/proxy:v0.3
# 2. Create users
infershield admin create-user alex@example.com
infershield admin create-user jordan@example.com
# 3. Each developer authenticates
infershield auth login openai --user alex@example.com- Week 1: OAuth device flow implementation
- Week 2: Token storage + refresh logic
- Week 3: CLI + proxy integration
- Week 4: Testing + documentation
- Week 5: v0.2 release (single-user OAuth)
Target: v0.2 release by mid-March 2026
- Token expiry: How long should tokens be cached? (Default: match provider expiry)
- Master key: Where should INFERSHIELD_MASTER_KEY come from? (User-provided, or generate + store?)
- Token sharing: Should tokens be shared across machines? (No for v0.2, optional for v0.3)
- Provider priority: Which OAuth provider first? (OpenAI or GitHub Copilot?)
- GitHub Device Flow Docs
- OpenAI OAuth Docs
- copilot-api-proxy Implementation
- OAuth 2.0 Device Flow RFC
Status: Design complete, ready for implementation Issue: #1