Files
Joel Salmon b8f176bb31 Initial commit: ImpactFlow Discovery + Google OAuth auth layer
Discovery service (pre-existing): FastAPI + async SQLAlchemy + Alembic +
SQLite + Anthropic, with a five-prompt static UI that produces an Enneagram
+ Ikigai profile.

Auth implementation (this change set) follows
Impact_Flow_Auth_Plan_OAuth.html, adapted to the discovery_conversation /
discovery_profile schema:

- app/auth.py: Google OAuth registration, JWT issue/decode, dual-auth
  dependency (Bearer JWT or X-API-Key), refresh-token hashing, domain
  allow-list, synthetic api-key-admin user
- app/tracking.py: ActivityTrackingMiddleware + log_activity helper;
  tags machine-to-machine calls source=mcp
- app/routers/auth.py: /api/auth/{login,callback,refresh,logout},
  /api/me, /api/me/{stats,sessions,sessions/{id}}
- app/routers/activity.py: /api/activity, /api/activity/summary,
  /api/admin/activity, plus prune_old_activity (90-day retention)
- app/routers/discovery.py: every route now user-scoped via the auth
  dependency; /discovery/profile/{user_id} -> /discovery/profile/me
- alembic/versions/002_add_auth.py: users, refresh_tokens, activity_log
- tests/test_auth.py: 8 tests covering 401 paths, X-API-Key admin
  resolution, JWT round-trip, admin gating, domain allow-list
- README.md: Authentication section, expanded env-var table, updated
  data-model and API-reference tables
- .env.example: new GOOGLE_*, JWT_*, IMPACTFLOW_API_KEY, CORS_*,
  ALLOWED_EMAIL_DOMAINS placeholders
- .gitignore: also exclude data/*.log

Tests: 19/19 pass (11 pre-existing + 8 new). smoke_test.py exercises the
full discovery flow under X-API-Key plus 401 paths, OAuth login redirect,
activity logging, and /api/me/stats.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 10:59:41 -05:00

68 lines
2.2 KiB
PowerShell

param(
[string]$ListenAddress = "0.0.0.0",
[string]$ConnectAddress = "wsl",
[int]$Port = 8011,
[int]$ConnectPort = 8011,
[string]$Distro = ""
)
$ErrorActionPreference = "Stop"
$principal = [Security.Principal.WindowsPrincipal]::new(
[Security.Principal.WindowsIdentity]::GetCurrent()
)
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
throw "Run this script from an elevated PowerShell prompt."
}
if ($ConnectAddress -eq "wsl") {
$wslArgs = @()
if ($Distro) {
$wslArgs += @("-d", $Distro)
}
$wslArgs += @("sh", "-lc", "hostname -I")
$wslIps = (& wsl.exe @wslArgs) -split "\s+"
$ConnectAddress = $wslIps |
Where-Object { $_ -match "^\d{1,3}(\.\d{1,3}){3}$" } |
Select-Object -First 1
if (-not $ConnectAddress) {
throw "Could not detect the WSL IP address. Make sure your WSL distro is running."
}
}
# Remove stale entries for this app. The old Tailscale-only entry can prevent
# this service from behaving like the other WSL-published services.
foreach ($entry in @(
@{ Address = $ListenAddress; Port = $Port },
@{ Address = "100.103.206.4"; Port = $Port },
@{ Address = "0.0.0.0"; Port = 8001 },
@{ Address = "100.103.206.4"; Port = 8001 }
)) {
netsh interface portproxy delete v4tov4 listenaddress=$entry.Address listenport=$entry.Port | Out-Null
}
netsh interface portproxy add v4tov4 listenaddress=$ListenAddress listenport=$Port connectaddress=$ConnectAddress connectport=$ConnectPort
if ($LASTEXITCODE -ne 0) {
throw "Failed to add the new portproxy entry."
}
$ruleName = "ImpactFlow Discovery $ListenAddress`:$Port"
$existingRule = Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue
if (-not $existingRule) {
$firewallArgs = @{
DisplayName = $ruleName
Direction = "Inbound"
Action = "Allow"
Protocol = "TCP"
LocalPort = $Port
}
if ($ListenAddress -ne "0.0.0.0") {
$firewallArgs.LocalAddress = $ListenAddress
}
New-NetFirewallRule @firewallArgs | Out-Null
}
Write-Output "Forwarding http://$ListenAddress`:$Port -> http://$ConnectAddress`:$ConnectPort"