@weirdfingers/baseboards 0.9.5 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +561 -469
- package/dist/index.js.map +1 -1
- package/package.json +2 -5
- package/templates/README.md +0 -122
- package/templates/api/.env.example +0 -65
- package/templates/api/ARTIFACT_RESOLUTION_GUIDE.md +0 -148
- package/templates/api/Dockerfile +0 -32
- package/templates/api/README.md +0 -264
- package/templates/api/alembic/env.py +0 -114
- package/templates/api/alembic/script.py.mako +0 -28
- package/templates/api/alembic/versions/20250101_000000_initial_schema.py +0 -506
- package/templates/api/alembic/versions/20251022_174729_remove_provider_name_from_generations.py +0 -75
- package/templates/api/alembic/versions/20251023_165852_switch_to_declarative_base_and_mapping.py +0 -467
- package/templates/api/alembic/versions/20251202_000000_add_artifact_lineage.py +0 -134
- package/templates/api/alembic/versions/2025925_62735_add_seed_data_for_default_tenant.py +0 -88
- package/templates/api/alembic.ini +0 -36
- package/templates/api/config/generators.yaml +0 -237
- package/templates/api/config/storage_config.yaml +0 -26
- package/templates/api/docs/ADDING_GENERATORS.md +0 -409
- package/templates/api/docs/GENERATORS_API.md +0 -502
- package/templates/api/docs/MIGRATIONS.md +0 -472
- package/templates/api/docs/TESTING_LIVE_APIS.md +0 -417
- package/templates/api/docs/storage_providers.md +0 -337
- package/templates/api/pyproject.toml +0 -205
- package/templates/api/src/boards/__init__.py +0 -10
- package/templates/api/src/boards/api/app.py +0 -172
- package/templates/api/src/boards/api/auth.py +0 -75
- package/templates/api/src/boards/api/endpoints/__init__.py +0 -3
- package/templates/api/src/boards/api/endpoints/jobs.py +0 -76
- package/templates/api/src/boards/api/endpoints/setup.py +0 -505
- package/templates/api/src/boards/api/endpoints/sse.py +0 -129
- package/templates/api/src/boards/api/endpoints/storage.py +0 -155
- package/templates/api/src/boards/api/endpoints/tenant_registration.py +0 -296
- package/templates/api/src/boards/api/endpoints/uploads.py +0 -149
- package/templates/api/src/boards/api/endpoints/webhooks.py +0 -13
- package/templates/api/src/boards/auth/__init__.py +0 -15
- package/templates/api/src/boards/auth/adapters/__init__.py +0 -27
- package/templates/api/src/boards/auth/adapters/auth0.py +0 -220
- package/templates/api/src/boards/auth/adapters/base.py +0 -73
- package/templates/api/src/boards/auth/adapters/clerk.py +0 -172
- package/templates/api/src/boards/auth/adapters/jwt.py +0 -122
- package/templates/api/src/boards/auth/adapters/none.py +0 -102
- package/templates/api/src/boards/auth/adapters/oidc.py +0 -284
- package/templates/api/src/boards/auth/adapters/supabase.py +0 -110
- package/templates/api/src/boards/auth/context.py +0 -35
- package/templates/api/src/boards/auth/factory.py +0 -129
- package/templates/api/src/boards/auth/middleware.py +0 -221
- package/templates/api/src/boards/auth/provisioning.py +0 -129
- package/templates/api/src/boards/auth/tenant_extraction.py +0 -278
- package/templates/api/src/boards/cli.py +0 -354
- package/templates/api/src/boards/config.py +0 -131
- package/templates/api/src/boards/database/__init__.py +0 -7
- package/templates/api/src/boards/database/cli.py +0 -110
- package/templates/api/src/boards/database/connection.py +0 -292
- package/templates/api/src/boards/database/models.py +0 -19
- package/templates/api/src/boards/database/seed_data.py +0 -182
- package/templates/api/src/boards/dbmodels/__init__.py +0 -441
- package/templates/api/src/boards/generators/__init__.py +0 -57
- package/templates/api/src/boards/generators/artifact_resolution.py +0 -405
- package/templates/api/src/boards/generators/artifacts.py +0 -53
- package/templates/api/src/boards/generators/base.py +0 -144
- package/templates/api/src/boards/generators/implementations/__init__.py +0 -14
- package/templates/api/src/boards/generators/implementations/fal/__init__.py +0 -25
- package/templates/api/src/boards/generators/implementations/fal/audio/__init__.py +0 -23
- package/templates/api/src/boards/generators/implementations/fal/audio/beatoven_music_generation.py +0 -171
- package/templates/api/src/boards/generators/implementations/fal/audio/beatoven_sound_effect_generation.py +0 -167
- package/templates/api/src/boards/generators/implementations/fal/audio/chatterbox_text_to_speech.py +0 -176
- package/templates/api/src/boards/generators/implementations/fal/audio/chatterbox_tts_turbo.py +0 -195
- package/templates/api/src/boards/generators/implementations/fal/audio/elevenlabs_sound_effects_v2.py +0 -194
- package/templates/api/src/boards/generators/implementations/fal/audio/elevenlabs_tts_eleven_v3.py +0 -209
- package/templates/api/src/boards/generators/implementations/fal/audio/fal_elevenlabs_tts_turbo_v2_5.py +0 -206
- package/templates/api/src/boards/generators/implementations/fal/audio/fal_minimax_speech_26_hd.py +0 -237
- package/templates/api/src/boards/generators/implementations/fal/audio/minimax_music_v2.py +0 -173
- package/templates/api/src/boards/generators/implementations/fal/audio/minimax_speech_2_6_turbo.py +0 -221
- package/templates/api/src/boards/generators/implementations/fal/image/__init__.py +0 -63
- package/templates/api/src/boards/generators/implementations/fal/image/bytedance_seedream_v45_edit.py +0 -219
- package/templates/api/src/boards/generators/implementations/fal/image/clarity_upscaler.py +0 -220
- package/templates/api/src/boards/generators/implementations/fal/image/crystal_upscaler.py +0 -173
- package/templates/api/src/boards/generators/implementations/fal/image/fal_ideogram_character.py +0 -227
- package/templates/api/src/boards/generators/implementations/fal/image/flux_2.py +0 -203
- package/templates/api/src/boards/generators/implementations/fal/image/flux_2_edit.py +0 -230
- package/templates/api/src/boards/generators/implementations/fal/image/flux_2_pro.py +0 -204
- package/templates/api/src/boards/generators/implementations/fal/image/flux_2_pro_edit.py +0 -221
- package/templates/api/src/boards/generators/implementations/fal/image/flux_pro_kontext.py +0 -216
- package/templates/api/src/boards/generators/implementations/fal/image/flux_pro_ultra.py +0 -197
- package/templates/api/src/boards/generators/implementations/fal/image/gemini_25_flash_image.py +0 -177
- package/templates/api/src/boards/generators/implementations/fal/image/gemini_25_flash_image_edit.py +0 -208
- package/templates/api/src/boards/generators/implementations/fal/image/gpt_image_15_edit.py +0 -216
- package/templates/api/src/boards/generators/implementations/fal/image/gpt_image_1_5.py +0 -177
- package/templates/api/src/boards/generators/implementations/fal/image/gpt_image_1_edit_image.py +0 -182
- package/templates/api/src/boards/generators/implementations/fal/image/gpt_image_1_mini.py +0 -167
- package/templates/api/src/boards/generators/implementations/fal/image/ideogram_character_edit.py +0 -299
- package/templates/api/src/boards/generators/implementations/fal/image/ideogram_v2.py +0 -190
- package/templates/api/src/boards/generators/implementations/fal/image/imagen4_preview.py +0 -191
- package/templates/api/src/boards/generators/implementations/fal/image/imagen4_preview_fast.py +0 -179
- package/templates/api/src/boards/generators/implementations/fal/image/nano_banana.py +0 -183
- package/templates/api/src/boards/generators/implementations/fal/image/nano_banana_edit.py +0 -212
- package/templates/api/src/boards/generators/implementations/fal/image/nano_banana_pro.py +0 -179
- package/templates/api/src/boards/generators/implementations/fal/image/nano_banana_pro_edit.py +0 -226
- package/templates/api/src/boards/generators/implementations/fal/image/qwen_image.py +0 -249
- package/templates/api/src/boards/generators/implementations/fal/image/qwen_image_edit.py +0 -244
- package/templates/api/src/boards/generators/implementations/fal/image/reve_edit.py +0 -178
- package/templates/api/src/boards/generators/implementations/fal/image/reve_text_to_image.py +0 -155
- package/templates/api/src/boards/generators/implementations/fal/image/seedream_v45_text_to_image.py +0 -180
- package/templates/api/src/boards/generators/implementations/fal/utils.py +0 -61
- package/templates/api/src/boards/generators/implementations/fal/video/__init__.py +0 -77
- package/templates/api/src/boards/generators/implementations/fal/video/bytedance_seedance_v1_pro_text_to_video.py +0 -209
- package/templates/api/src/boards/generators/implementations/fal/video/creatify_lipsync.py +0 -161
- package/templates/api/src/boards/generators/implementations/fal/video/fal_bytedance_seedance_v1_pro_image_to_video.py +0 -222
- package/templates/api/src/boards/generators/implementations/fal/video/fal_minimax_hailuo_02_standard_text_to_video.py +0 -152
- package/templates/api/src/boards/generators/implementations/fal/video/fal_pixverse_lipsync.py +0 -197
- package/templates/api/src/boards/generators/implementations/fal/video/fal_sora_2_text_to_video.py +0 -173
- package/templates/api/src/boards/generators/implementations/fal/video/infinitalk.py +0 -221
- package/templates/api/src/boards/generators/implementations/fal/video/kling_video_ai_avatar_v2_pro.py +0 -168
- package/templates/api/src/boards/generators/implementations/fal/video/kling_video_ai_avatar_v2_standard.py +0 -159
- package/templates/api/src/boards/generators/implementations/fal/video/kling_video_v2_5_turbo_pro_image_to_video.py +0 -175
- package/templates/api/src/boards/generators/implementations/fal/video/kling_video_v2_5_turbo_pro_text_to_video.py +0 -168
- package/templates/api/src/boards/generators/implementations/fal/video/minimax_hailuo_2_3_pro_image_to_video.py +0 -153
- package/templates/api/src/boards/generators/implementations/fal/video/sora2_image_to_video.py +0 -172
- package/templates/api/src/boards/generators/implementations/fal/video/sora_2_image_to_video_pro.py +0 -175
- package/templates/api/src/boards/generators/implementations/fal/video/sora_2_text_to_video_pro.py +0 -163
- package/templates/api/src/boards/generators/implementations/fal/video/sync_lipsync_v2.py +0 -167
- package/templates/api/src/boards/generators/implementations/fal/video/sync_lipsync_v2_pro.py +0 -155
- package/templates/api/src/boards/generators/implementations/fal/video/veed_fabric_1_0.py +0 -180
- package/templates/api/src/boards/generators/implementations/fal/video/veed_lipsync.py +0 -174
- package/templates/api/src/boards/generators/implementations/fal/video/veo3.py +0 -194
- package/templates/api/src/boards/generators/implementations/fal/video/veo31.py +0 -190
- package/templates/api/src/boards/generators/implementations/fal/video/veo31_fast.py +0 -190
- package/templates/api/src/boards/generators/implementations/fal/video/veo31_fast_image_to_video.py +0 -191
- package/templates/api/src/boards/generators/implementations/fal/video/veo31_first_last_frame_to_video.py +0 -187
- package/templates/api/src/boards/generators/implementations/fal/video/veo31_image_to_video.py +0 -183
- package/templates/api/src/boards/generators/implementations/fal/video/veo31_reference_to_video.py +0 -172
- package/templates/api/src/boards/generators/implementations/fal/video/wan_25_preview_image_to_video.py +0 -212
- package/templates/api/src/boards/generators/implementations/fal/video/wan_25_preview_text_to_video.py +0 -208
- package/templates/api/src/boards/generators/implementations/fal/video/wan_pro_image_to_video.py +0 -158
- package/templates/api/src/boards/generators/implementations/kie/__init__.py +0 -11
- package/templates/api/src/boards/generators/implementations/kie/base.py +0 -316
- package/templates/api/src/boards/generators/implementations/kie/image/__init__.py +0 -3
- package/templates/api/src/boards/generators/implementations/kie/image/nano_banana_edit.py +0 -190
- package/templates/api/src/boards/generators/implementations/kie/utils.py +0 -98
- package/templates/api/src/boards/generators/implementations/kie/video/__init__.py +0 -8
- package/templates/api/src/boards/generators/implementations/kie/video/veo3.py +0 -161
- package/templates/api/src/boards/generators/implementations/openai/__init__.py +0 -1
- package/templates/api/src/boards/generators/implementations/openai/audio/__init__.py +0 -1
- package/templates/api/src/boards/generators/implementations/openai/audio/whisper.py +0 -69
- package/templates/api/src/boards/generators/implementations/openai/image/__init__.py +0 -1
- package/templates/api/src/boards/generators/implementations/openai/image/dalle3.py +0 -96
- package/templates/api/src/boards/generators/implementations/replicate/__init__.py +0 -1
- package/templates/api/src/boards/generators/implementations/replicate/image/__init__.py +0 -1
- package/templates/api/src/boards/generators/implementations/replicate/image/flux_pro.py +0 -88
- package/templates/api/src/boards/generators/implementations/replicate/video/__init__.py +0 -1
- package/templates/api/src/boards/generators/implementations/replicate/video/lipsync.py +0 -73
- package/templates/api/src/boards/generators/loader.py +0 -253
- package/templates/api/src/boards/generators/registry.py +0 -114
- package/templates/api/src/boards/generators/resolution.py +0 -632
- package/templates/api/src/boards/generators/testmods/class_gen.py +0 -34
- package/templates/api/src/boards/generators/testmods/import_side_effect.py +0 -35
- package/templates/api/src/boards/graphql/__init__.py +0 -7
- package/templates/api/src/boards/graphql/access_control.py +0 -136
- package/templates/api/src/boards/graphql/mutations/root.py +0 -148
- package/templates/api/src/boards/graphql/queries/root.py +0 -116
- package/templates/api/src/boards/graphql/resolvers/__init__.py +0 -8
- package/templates/api/src/boards/graphql/resolvers/auth.py +0 -12
- package/templates/api/src/boards/graphql/resolvers/board.py +0 -1053
- package/templates/api/src/boards/graphql/resolvers/generation.py +0 -666
- package/templates/api/src/boards/graphql/resolvers/generator.py +0 -50
- package/templates/api/src/boards/graphql/resolvers/lineage.py +0 -381
- package/templates/api/src/boards/graphql/resolvers/upload.py +0 -463
- package/templates/api/src/boards/graphql/resolvers/user.py +0 -25
- package/templates/api/src/boards/graphql/schema.py +0 -81
- package/templates/api/src/boards/graphql/types/board.py +0 -102
- package/templates/api/src/boards/graphql/types/generation.py +0 -166
- package/templates/api/src/boards/graphql/types/generator.py +0 -17
- package/templates/api/src/boards/graphql/types/user.py +0 -47
- package/templates/api/src/boards/jobs/repository.py +0 -153
- package/templates/api/src/boards/logging.py +0 -195
- package/templates/api/src/boards/middleware.py +0 -339
- package/templates/api/src/boards/progress/__init__.py +0 -4
- package/templates/api/src/boards/progress/models.py +0 -25
- package/templates/api/src/boards/progress/publisher.py +0 -64
- package/templates/api/src/boards/py.typed +0 -0
- package/templates/api/src/boards/redis_pool.py +0 -118
- package/templates/api/src/boards/storage/__init__.py +0 -52
- package/templates/api/src/boards/storage/base.py +0 -363
- package/templates/api/src/boards/storage/config.py +0 -187
- package/templates/api/src/boards/storage/factory.py +0 -288
- package/templates/api/src/boards/storage/implementations/__init__.py +0 -27
- package/templates/api/src/boards/storage/implementations/gcs.py +0 -340
- package/templates/api/src/boards/storage/implementations/local.py +0 -201
- package/templates/api/src/boards/storage/implementations/s3.py +0 -294
- package/templates/api/src/boards/storage/implementations/supabase.py +0 -218
- package/templates/api/src/boards/tenant_isolation.py +0 -446
- package/templates/api/src/boards/validation.py +0 -262
- package/templates/api/src/boards/workers/__init__.py +0 -1
- package/templates/api/src/boards/workers/actors.py +0 -274
- package/templates/api/src/boards/workers/cli.py +0 -125
- package/templates/api/src/boards/workers/context.py +0 -348
- package/templates/api/src/boards/workers/middleware.py +0 -58
- package/templates/api/src/py.typed +0 -0
- package/templates/compose.web.yaml +0 -35
- package/templates/compose.yaml +0 -116
- package/templates/docker/env.example +0 -23
- package/templates/web/.env.example +0 -28
- package/templates/web/Dockerfile +0 -51
- package/templates/web/components.json +0 -22
- package/templates/web/imageLoader.js +0 -18
- package/templates/web/next-env.d.ts +0 -5
- package/templates/web/next.config.js +0 -36
- package/templates/web/package.json +0 -41
- package/templates/web/postcss.config.mjs +0 -7
- package/templates/web/public/favicon.ico +0 -0
- package/templates/web/src/app/boards/[boardId]/page.tsx +0 -353
- package/templates/web/src/app/globals.css +0 -123
- package/templates/web/src/app/layout.tsx +0 -31
- package/templates/web/src/app/lineage/[generationId]/page.tsx +0 -235
- package/templates/web/src/app/page.tsx +0 -35
- package/templates/web/src/app/providers.tsx +0 -18
- package/templates/web/src/components/boards/ArtifactInputSlots.tsx +0 -206
- package/templates/web/src/components/boards/ArtifactPreview.tsx +0 -466
- package/templates/web/src/components/boards/GenerationGrid.tsx +0 -282
- package/templates/web/src/components/boards/GenerationInput.tsx +0 -370
- package/templates/web/src/components/boards/GeneratorSelector.tsx +0 -272
- package/templates/web/src/components/boards/UploadArtifact.tsx +0 -563
- package/templates/web/src/components/header.tsx +0 -32
- package/templates/web/src/components/theme-provider.tsx +0 -10
- package/templates/web/src/components/theme-toggle.tsx +0 -75
- package/templates/web/src/components/ui/alert-dialog.tsx +0 -157
- package/templates/web/src/components/ui/button.tsx +0 -58
- package/templates/web/src/components/ui/card.tsx +0 -92
- package/templates/web/src/components/ui/dropdown-menu.tsx +0 -200
- package/templates/web/src/components/ui/navigation-menu.tsx +0 -168
- package/templates/web/src/components/ui/toast.tsx +0 -128
- package/templates/web/src/components/ui/toaster.tsx +0 -35
- package/templates/web/src/components/ui/use-toast.ts +0 -187
- package/templates/web/src/hooks/useGeneratorMRU.ts +0 -57
- package/templates/web/src/lib/utils.ts +0 -6
- package/templates/web/tsconfig.json +0 -41
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
"""Generic OIDC authentication adapter."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import time
|
|
6
|
-
from typing import Any
|
|
7
|
-
from uuid import UUID
|
|
8
|
-
|
|
9
|
-
import httpx
|
|
10
|
-
import jwt
|
|
11
|
-
|
|
12
|
-
from ...logging import get_logger
|
|
13
|
-
from .base import AuthenticationError, Principal
|
|
14
|
-
|
|
15
|
-
logger = get_logger(__name__)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class OIDCAdapter:
|
|
19
|
-
"""Generic OIDC authentication adapter."""
|
|
20
|
-
|
|
21
|
-
def __init__(
|
|
22
|
-
self,
|
|
23
|
-
issuer: str,
|
|
24
|
-
client_id: str,
|
|
25
|
-
client_secret: str | None = None,
|
|
26
|
-
audience: str | None = None,
|
|
27
|
-
jwks_url: str | None = None,
|
|
28
|
-
jwks_cache_ttl: int = 3600, # 1 hour default TTL
|
|
29
|
-
):
|
|
30
|
-
"""
|
|
31
|
-
Initialize OIDC adapter.
|
|
32
|
-
|
|
33
|
-
Args:
|
|
34
|
-
issuer: OIDC issuer URL (e.g., "https://accounts.google.com")
|
|
35
|
-
client_id: OIDC client ID
|
|
36
|
-
client_secret: Optional client secret for API calls
|
|
37
|
-
audience: Optional audience/client_id for token validation
|
|
38
|
-
jwks_url: Optional JWKS URL (auto-discovered if not provided)
|
|
39
|
-
jwks_cache_ttl: JWKS cache TTL in seconds (default: 3600 = 1 hour)
|
|
40
|
-
"""
|
|
41
|
-
self.issuer = issuer.rstrip("/")
|
|
42
|
-
self.client_id = client_id
|
|
43
|
-
self.client_secret = client_secret
|
|
44
|
-
self.audience = audience or client_id
|
|
45
|
-
self.jwks_url = jwks_url
|
|
46
|
-
self.jwks_cache_ttl = jwks_cache_ttl
|
|
47
|
-
self._oidc_config: dict[str, Any] = {}
|
|
48
|
-
# Cache structure: {"data": jwks_data, "expires_at": timestamp}
|
|
49
|
-
self._jwks_cache: dict[str, Any] = {}
|
|
50
|
-
self._http_client = httpx.AsyncClient()
|
|
51
|
-
|
|
52
|
-
async def verify_token(self, token: str) -> Principal:
|
|
53
|
-
"""Verify an OIDC JWT token and return the principal."""
|
|
54
|
-
try:
|
|
55
|
-
# JWT library already imported
|
|
56
|
-
from jwt.exceptions import InvalidTokenError
|
|
57
|
-
|
|
58
|
-
# Get OIDC configuration and JWKS
|
|
59
|
-
await self._ensure_oidc_config()
|
|
60
|
-
jwks = await self._get_jwks()
|
|
61
|
-
|
|
62
|
-
# Decode JWT header to get key ID
|
|
63
|
-
unverified_header = jwt.get_unverified_header(token)
|
|
64
|
-
kid = unverified_header.get("kid")
|
|
65
|
-
|
|
66
|
-
if not kid:
|
|
67
|
-
raise AuthenticationError("Missing 'kid' in JWT header")
|
|
68
|
-
|
|
69
|
-
# Find the matching key
|
|
70
|
-
key = None
|
|
71
|
-
for jwk in jwks.get("keys", []):
|
|
72
|
-
if jwk.get("kid") == kid:
|
|
73
|
-
# Store the JWK - PyJWT handles RSA/EC conversion internally
|
|
74
|
-
key = jwk
|
|
75
|
-
break
|
|
76
|
-
|
|
77
|
-
if not key:
|
|
78
|
-
raise AuthenticationError(f"Unable to find key with kid: {kid}")
|
|
79
|
-
|
|
80
|
-
# Determine algorithm from JWK
|
|
81
|
-
alg = jwk.get("alg", "RS256")
|
|
82
|
-
|
|
83
|
-
# Verify and decode the token
|
|
84
|
-
payload = jwt.decode(
|
|
85
|
-
token,
|
|
86
|
-
key,
|
|
87
|
-
algorithms=[alg],
|
|
88
|
-
issuer=self.issuer,
|
|
89
|
-
audience=self.audience,
|
|
90
|
-
options={
|
|
91
|
-
"verify_exp": True,
|
|
92
|
-
"verify_nbf": True,
|
|
93
|
-
"verify_iat": True,
|
|
94
|
-
"verify_aud": True,
|
|
95
|
-
"verify_iss": True,
|
|
96
|
-
},
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
# Extract required claims
|
|
100
|
-
subject = payload.get("sub")
|
|
101
|
-
if not subject:
|
|
102
|
-
raise AuthenticationError("Missing 'sub' claim in token")
|
|
103
|
-
|
|
104
|
-
# Build principal from OIDC claims
|
|
105
|
-
principal = Principal(
|
|
106
|
-
provider="oidc",
|
|
107
|
-
subject=subject,
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
# Add optional standard OIDC claims
|
|
111
|
-
if email := payload.get("email"):
|
|
112
|
-
principal["email"] = email
|
|
113
|
-
|
|
114
|
-
# Extract name information
|
|
115
|
-
if name := payload.get("name"):
|
|
116
|
-
principal["display_name"] = name
|
|
117
|
-
elif given_name := payload.get("given_name"):
|
|
118
|
-
family_name = payload.get("family_name", "")
|
|
119
|
-
principal["display_name"] = f"{given_name} {family_name}".strip()
|
|
120
|
-
elif preferred_username := payload.get("preferred_username"):
|
|
121
|
-
principal["display_name"] = preferred_username
|
|
122
|
-
|
|
123
|
-
if picture := payload.get("picture"):
|
|
124
|
-
principal["avatar_url"] = picture
|
|
125
|
-
|
|
126
|
-
# Store all claims for additional context
|
|
127
|
-
principal["claims"] = payload
|
|
128
|
-
|
|
129
|
-
return principal
|
|
130
|
-
|
|
131
|
-
except ImportError as e:
|
|
132
|
-
raise AuthenticationError("PyJWT is required for OIDC authentication") from e
|
|
133
|
-
except InvalidTokenError as e:
|
|
134
|
-
logger.warning(f"OIDC JWT token validation failed: {e}")
|
|
135
|
-
raise AuthenticationError(f"Invalid token: {e}") from e
|
|
136
|
-
except Exception as e:
|
|
137
|
-
logger.error(f"Unexpected error verifying OIDC token: {e}")
|
|
138
|
-
raise AuthenticationError("Token verification failed") from e
|
|
139
|
-
|
|
140
|
-
async def issue_token(self, user_id: UUID | None = None, claims: dict | None = None) -> str:
|
|
141
|
-
"""
|
|
142
|
-
Issue a new token via OIDC provider (rarely supported).
|
|
143
|
-
|
|
144
|
-
Most OIDC providers handle token issuance via client libraries.
|
|
145
|
-
"""
|
|
146
|
-
raise NotImplementedError("Token issuance should be handled by OIDC client libraries")
|
|
147
|
-
|
|
148
|
-
async def get_user_info(self, token: str) -> dict:
|
|
149
|
-
"""Get additional user information from OIDC userinfo endpoint."""
|
|
150
|
-
try:
|
|
151
|
-
await self._ensure_oidc_config()
|
|
152
|
-
userinfo_endpoint = self._oidc_config.get("userinfo_endpoint")
|
|
153
|
-
|
|
154
|
-
if not userinfo_endpoint:
|
|
155
|
-
logger.warning("No userinfo_endpoint in OIDC configuration")
|
|
156
|
-
return {}
|
|
157
|
-
|
|
158
|
-
response = await self._http_client.get(
|
|
159
|
-
userinfo_endpoint,
|
|
160
|
-
headers={
|
|
161
|
-
"Authorization": f"Bearer {token}",
|
|
162
|
-
"Content-Type": "application/json",
|
|
163
|
-
},
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
if response.status_code == 200:
|
|
167
|
-
return response.json()
|
|
168
|
-
else:
|
|
169
|
-
logger.warning(f"Failed to get OIDC user info: {response.status_code}")
|
|
170
|
-
return {}
|
|
171
|
-
|
|
172
|
-
except Exception as e:
|
|
173
|
-
logger.warning(f"Failed to get OIDC user info: {e}")
|
|
174
|
-
return {}
|
|
175
|
-
|
|
176
|
-
async def _ensure_oidc_config(self) -> None:
|
|
177
|
-
"""Ensure OIDC discovery configuration is loaded."""
|
|
178
|
-
if self._oidc_config:
|
|
179
|
-
return
|
|
180
|
-
|
|
181
|
-
try:
|
|
182
|
-
# OIDC Discovery
|
|
183
|
-
discovery_url = f"{self.issuer}/.well-known/openid_configuration"
|
|
184
|
-
response = await self._http_client.get(discovery_url)
|
|
185
|
-
response.raise_for_status()
|
|
186
|
-
|
|
187
|
-
self._oidc_config = response.json()
|
|
188
|
-
|
|
189
|
-
# Set JWKS URL if not provided
|
|
190
|
-
if not self.jwks_url:
|
|
191
|
-
self.jwks_url = self._oidc_config.get("jwks_uri")
|
|
192
|
-
|
|
193
|
-
if not self.jwks_url:
|
|
194
|
-
raise AuthenticationError("Unable to determine JWKS URL")
|
|
195
|
-
|
|
196
|
-
except Exception as e:
|
|
197
|
-
logger.error(f"Failed to load OIDC configuration: {e}")
|
|
198
|
-
raise AuthenticationError("Unable to load OIDC configuration") from e
|
|
199
|
-
|
|
200
|
-
async def _get_jwks(self) -> dict[str, Any]:
|
|
201
|
-
"""Get JWKS from OIDC provider for JWT verification with TTL caching."""
|
|
202
|
-
try:
|
|
203
|
-
# Ensure we have JWKS URL
|
|
204
|
-
if not self.jwks_url:
|
|
205
|
-
await self._ensure_oidc_config()
|
|
206
|
-
|
|
207
|
-
current_time = time.time()
|
|
208
|
-
|
|
209
|
-
# Check cache first with TTL
|
|
210
|
-
if (
|
|
211
|
-
self._jwks_cache
|
|
212
|
-
and "data" in self._jwks_cache
|
|
213
|
-
and "expires_at" in self._jwks_cache
|
|
214
|
-
and current_time < self._jwks_cache["expires_at"]
|
|
215
|
-
):
|
|
216
|
-
logger.debug(
|
|
217
|
-
"Returning cached JWKS",
|
|
218
|
-
cache_expires_in=int(self._jwks_cache["expires_at"] - current_time),
|
|
219
|
-
)
|
|
220
|
-
return self._jwks_cache["data"]
|
|
221
|
-
|
|
222
|
-
# Cache expired or empty, fetch fresh JWKS
|
|
223
|
-
if self._jwks_cache:
|
|
224
|
-
logger.info(
|
|
225
|
-
"JWKS cache expired, fetching fresh data",
|
|
226
|
-
cache_age=int(
|
|
227
|
-
current_time
|
|
228
|
-
- (self._jwks_cache.get("expires_at", current_time) - self.jwks_cache_ttl)
|
|
229
|
-
),
|
|
230
|
-
)
|
|
231
|
-
|
|
232
|
-
# Ensure jwks_url is available after config check
|
|
233
|
-
if not self.jwks_url:
|
|
234
|
-
raise AuthenticationError("JWKS URL not available after configuration")
|
|
235
|
-
|
|
236
|
-
logger.debug("Fetching JWKS from provider", jwks_url=self.jwks_url)
|
|
237
|
-
response = await self._http_client.get(self.jwks_url)
|
|
238
|
-
response.raise_for_status()
|
|
239
|
-
|
|
240
|
-
jwks = response.json()
|
|
241
|
-
|
|
242
|
-
# Determine TTL from cache-control header or use default
|
|
243
|
-
cache_ttl = self.jwks_cache_ttl
|
|
244
|
-
cache_control = response.headers.get("cache-control", "")
|
|
245
|
-
if "max-age=" in cache_control:
|
|
246
|
-
try:
|
|
247
|
-
# Extract max-age value from cache-control header
|
|
248
|
-
max_age_str = cache_control.split("max-age=")[1].split(",")[0].split(";")[0]
|
|
249
|
-
header_ttl = int(max_age_str)
|
|
250
|
-
# Use the smaller of header TTL and configured TTL for security
|
|
251
|
-
cache_ttl = min(header_ttl, self.jwks_cache_ttl)
|
|
252
|
-
logger.debug(
|
|
253
|
-
"Using cache-control max-age",
|
|
254
|
-
header_ttl=header_ttl,
|
|
255
|
-
effective_ttl=cache_ttl,
|
|
256
|
-
)
|
|
257
|
-
except (ValueError, IndexError):
|
|
258
|
-
logger.debug(
|
|
259
|
-
"Could not parse cache-control max-age, using default TTL",
|
|
260
|
-
default_ttl=cache_ttl,
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
# Update cache with TTL
|
|
264
|
-
expires_at = current_time + cache_ttl
|
|
265
|
-
self._jwks_cache = {"data": jwks, "expires_at": expires_at}
|
|
266
|
-
|
|
267
|
-
logger.info(
|
|
268
|
-
"Updated JWKS cache",
|
|
269
|
-
cache_ttl=cache_ttl,
|
|
270
|
-
expires_at=int(expires_at),
|
|
271
|
-
keys_count=len(jwks.get("keys", [])),
|
|
272
|
-
)
|
|
273
|
-
|
|
274
|
-
return jwks
|
|
275
|
-
|
|
276
|
-
except Exception as e:
|
|
277
|
-
logger.error("Failed to fetch JWKS from OIDC provider", error=str(e))
|
|
278
|
-
raise AuthenticationError("Unable to verify token - JWKS unavailable") from e
|
|
279
|
-
|
|
280
|
-
async def __aenter__(self):
|
|
281
|
-
return self
|
|
282
|
-
|
|
283
|
-
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
284
|
-
await self._http_client.aclose()
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"""Supabase authentication adapter."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from uuid import UUID
|
|
6
|
-
|
|
7
|
-
import jwt
|
|
8
|
-
from supabase import Client, create_client
|
|
9
|
-
|
|
10
|
-
from ...logging import get_logger
|
|
11
|
-
from .base import AuthenticationError, Principal
|
|
12
|
-
|
|
13
|
-
logger = get_logger(__name__)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class SupabaseAuthAdapter:
|
|
17
|
-
"""Supabase authentication adapter."""
|
|
18
|
-
|
|
19
|
-
def __init__(self, url: str, service_role_key: str):
|
|
20
|
-
"""
|
|
21
|
-
Initialize Supabase adapter.
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
url: Supabase project URL
|
|
25
|
-
service_role_key: Service role key for admin operations
|
|
26
|
-
"""
|
|
27
|
-
self.url = url
|
|
28
|
-
self.service_role_key = service_role_key
|
|
29
|
-
self.client: Client = create_client(url, service_role_key)
|
|
30
|
-
|
|
31
|
-
async def verify_token(self, token: str) -> Principal:
|
|
32
|
-
"""Verify a Supabase JWT token and return the principal."""
|
|
33
|
-
try:
|
|
34
|
-
# Get user info from Supabase auth
|
|
35
|
-
user_response = self.client.auth.get_user(token)
|
|
36
|
-
|
|
37
|
-
if not user_response or not user_response.user:
|
|
38
|
-
raise AuthenticationError("Invalid or expired token")
|
|
39
|
-
|
|
40
|
-
user = user_response.user
|
|
41
|
-
|
|
42
|
-
# Build principal from Supabase user
|
|
43
|
-
principal = Principal(
|
|
44
|
-
provider="supabase",
|
|
45
|
-
subject=user.id,
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
# Add optional user data
|
|
49
|
-
if user.email:
|
|
50
|
-
principal["email"] = user.email
|
|
51
|
-
|
|
52
|
-
# Extract display name from user metadata
|
|
53
|
-
if user.user_metadata:
|
|
54
|
-
if display_name := user.user_metadata.get("display_name") or user.user_metadata.get(
|
|
55
|
-
"full_name"
|
|
56
|
-
):
|
|
57
|
-
principal["display_name"] = display_name
|
|
58
|
-
if avatar_url := user.user_metadata.get("avatar_url"):
|
|
59
|
-
principal["avatar_url"] = avatar_url
|
|
60
|
-
|
|
61
|
-
# Store raw claims for additional context
|
|
62
|
-
try:
|
|
63
|
-
# Decode JWT without verification to get all claims
|
|
64
|
-
# (we already verified via Supabase API)
|
|
65
|
-
decoded = jwt.decode(token, options={"verify_signature": False})
|
|
66
|
-
principal["claims"] = decoded
|
|
67
|
-
except Exception as e:
|
|
68
|
-
logger.debug("Could not decode JWT claims", error=str(e))
|
|
69
|
-
|
|
70
|
-
return principal
|
|
71
|
-
|
|
72
|
-
except Exception as e:
|
|
73
|
-
logger.warning("Supabase token validation failed", error=str(e))
|
|
74
|
-
raise AuthenticationError(f"Invalid token: {e}") from e
|
|
75
|
-
|
|
76
|
-
async def issue_token(self, user_id: UUID | None = None, claims: dict | None = None) -> str:
|
|
77
|
-
"""
|
|
78
|
-
Issue a new token via Supabase (not commonly used).
|
|
79
|
-
|
|
80
|
-
Note: Supabase typically handles token issuance on the client side.
|
|
81
|
-
This method is provided for completeness but may not be used in practice.
|
|
82
|
-
"""
|
|
83
|
-
# Supabase doesn't provide a direct server-side token issuance API
|
|
84
|
-
# This would typically be done on the client side
|
|
85
|
-
raise NotImplementedError("Token issuance should be handled by Supabase client libraries")
|
|
86
|
-
|
|
87
|
-
async def get_user_info(self, token: str) -> dict:
|
|
88
|
-
"""Get additional user information from Supabase."""
|
|
89
|
-
try:
|
|
90
|
-
user_response = self.client.auth.get_user(token)
|
|
91
|
-
|
|
92
|
-
if not user_response or not user_response.user:
|
|
93
|
-
return {}
|
|
94
|
-
|
|
95
|
-
user = user_response.user
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
"id": user.id,
|
|
99
|
-
"email": user.email,
|
|
100
|
-
"email_confirmed_at": user.email_confirmed_at,
|
|
101
|
-
"phone": user.phone,
|
|
102
|
-
"created_at": user.created_at,
|
|
103
|
-
"updated_at": user.updated_at,
|
|
104
|
-
"user_metadata": user.user_metadata,
|
|
105
|
-
"app_metadata": user.app_metadata,
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
except Exception as e:
|
|
109
|
-
logger.warning("Failed to get Supabase user info", error=str(e))
|
|
110
|
-
return {}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"""Authentication context for request handling."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from dataclasses import dataclass
|
|
6
|
-
from uuid import UUID
|
|
7
|
-
|
|
8
|
-
from .adapters.base import Principal
|
|
9
|
-
|
|
10
|
-
# Default tenant UUID for single-tenant deployments or when tenant resolution fails
|
|
11
|
-
# This null UUID (00000000-0000-0000-0000-000000000000) is used when:
|
|
12
|
-
# - Running in single-tenant mode
|
|
13
|
-
# - Local development without multi-tenant setup
|
|
14
|
-
# - Tenant slug resolution fails
|
|
15
|
-
DEFAULT_TENANT_UUID = UUID("00000000-0000-0000-0000-000000000000")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@dataclass
|
|
19
|
-
class AuthContext:
|
|
20
|
-
"""Runtime authentication context for a request."""
|
|
21
|
-
|
|
22
|
-
user_id: UUID | None
|
|
23
|
-
tenant_id: UUID
|
|
24
|
-
principal: Principal | None
|
|
25
|
-
token: str | None
|
|
26
|
-
|
|
27
|
-
@property
|
|
28
|
-
def is_authenticated(self) -> bool:
|
|
29
|
-
"""Check if the request is authenticated."""
|
|
30
|
-
return self.user_id is not None and self.principal is not None
|
|
31
|
-
|
|
32
|
-
@property
|
|
33
|
-
def provider(self) -> str | None:
|
|
34
|
-
"""Get the authentication provider name."""
|
|
35
|
-
return self.principal["provider"] if self.principal else None
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"""Factory for creating auth adapters based on configuration."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import json
|
|
6
|
-
import os
|
|
7
|
-
|
|
8
|
-
from .adapters.auth0 import Auth0OIDCAdapter
|
|
9
|
-
from .adapters.base import AuthAdapter
|
|
10
|
-
from .adapters.clerk import ClerkAuthAdapter
|
|
11
|
-
from .adapters.jwt import JWTAuthAdapter
|
|
12
|
-
from .adapters.none import NoAuthAdapter
|
|
13
|
-
from .adapters.oidc import OIDCAdapter
|
|
14
|
-
|
|
15
|
-
# Optional Supabase adapter - imported conditionally
|
|
16
|
-
try:
|
|
17
|
-
from .adapters.supabase import SupabaseAuthAdapter
|
|
18
|
-
|
|
19
|
-
SUPABASE_AVAILABLE = True
|
|
20
|
-
except ImportError:
|
|
21
|
-
SUPABASE_AVAILABLE = False
|
|
22
|
-
SupabaseAuthAdapter = None # type: ignore
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def get_auth_adapter() -> AuthAdapter:
|
|
26
|
-
"""Create and return the configured auth adapter."""
|
|
27
|
-
provider = os.getenv("BOARDS_AUTH_PROVIDER", "none") # Default to no-auth for dev
|
|
28
|
-
config_str = os.getenv("BOARDS_AUTH_CONFIG", "{}")
|
|
29
|
-
|
|
30
|
-
try:
|
|
31
|
-
config = json.loads(config_str)
|
|
32
|
-
except json.JSONDecodeError:
|
|
33
|
-
config = {}
|
|
34
|
-
|
|
35
|
-
if provider == "none":
|
|
36
|
-
# No-auth mode for local development
|
|
37
|
-
return NoAuthAdapter(
|
|
38
|
-
default_user_id=config.get("default_user_id", "dev-user"),
|
|
39
|
-
default_tenant=config.get("default_tenant", "default"),
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
elif provider == "jwt":
|
|
43
|
-
secret_key = config.get("secret_key") or os.getenv("BOARDS_JWT_SECRET")
|
|
44
|
-
if not secret_key:
|
|
45
|
-
raise ValueError(
|
|
46
|
-
"JWT secret key is required. Set BOARDS_JWT_SECRET or provide in config."
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
return JWTAuthAdapter(
|
|
50
|
-
secret_key=secret_key,
|
|
51
|
-
algorithm=config.get("algorithm", "HS256"),
|
|
52
|
-
issuer=config.get("issuer", "boards"),
|
|
53
|
-
audience=config.get("audience", "boards-api"),
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
elif provider == "supabase":
|
|
57
|
-
if not SUPABASE_AVAILABLE:
|
|
58
|
-
raise ValueError(
|
|
59
|
-
"Supabase auth provider is not available. "
|
|
60
|
-
"Install the supabase package: pip install 'weirdfingers-boards[auth-supabase]'"
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
url = config.get("url") or os.getenv("SUPABASE_URL")
|
|
64
|
-
service_role_key = config.get("service_role_key") or os.getenv("SUPABASE_SERVICE_ROLE_KEY")
|
|
65
|
-
|
|
66
|
-
if not url or not service_role_key:
|
|
67
|
-
raise ValueError(
|
|
68
|
-
"Supabase URL and service role key are required. "
|
|
69
|
-
"Set SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY or provide in config."
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
return SupabaseAuthAdapter(url=url, service_role_key=service_role_key) # type: ignore
|
|
73
|
-
|
|
74
|
-
elif provider == "clerk":
|
|
75
|
-
secret_key = config.get("secret_key") or os.getenv("CLERK_SECRET_KEY")
|
|
76
|
-
if not secret_key:
|
|
77
|
-
raise ValueError(
|
|
78
|
-
"Clerk secret key is required. Set CLERK_SECRET_KEY or provide in config."
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
return ClerkAuthAdapter(
|
|
82
|
-
secret_key=secret_key,
|
|
83
|
-
jwks_url=config.get("jwks_url"),
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
elif provider == "auth0":
|
|
87
|
-
domain = config.get("domain") or os.getenv("AUTH0_DOMAIN")
|
|
88
|
-
audience = config.get("audience") or os.getenv("AUTH0_AUDIENCE")
|
|
89
|
-
|
|
90
|
-
if not domain or not audience:
|
|
91
|
-
raise ValueError(
|
|
92
|
-
"Auth0 domain and audience are required. "
|
|
93
|
-
"Set AUTH0_DOMAIN and AUTH0_AUDIENCE or provide in config."
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
return Auth0OIDCAdapter(
|
|
97
|
-
domain=domain,
|
|
98
|
-
audience=audience,
|
|
99
|
-
client_id=config.get("client_id") or os.getenv("AUTH0_CLIENT_ID"),
|
|
100
|
-
client_secret=config.get("client_secret") or os.getenv("AUTH0_CLIENT_SECRET"),
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
elif provider == "oidc":
|
|
104
|
-
issuer = config.get("issuer") or os.getenv("OIDC_ISSUER")
|
|
105
|
-
client_id = config.get("client_id") or os.getenv("OIDC_CLIENT_ID")
|
|
106
|
-
|
|
107
|
-
if not issuer or not client_id:
|
|
108
|
-
raise ValueError(
|
|
109
|
-
"OIDC issuer and client_id are required. "
|
|
110
|
-
"Set OIDC_ISSUER and OIDC_CLIENT_ID or provide in config."
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
return OIDCAdapter(
|
|
114
|
-
issuer=issuer,
|
|
115
|
-
client_id=client_id,
|
|
116
|
-
client_secret=config.get("client_secret") or os.getenv("OIDC_CLIENT_SECRET"),
|
|
117
|
-
audience=config.get("audience") or os.getenv("OIDC_AUDIENCE"),
|
|
118
|
-
jwks_url=config.get("jwks_url") or os.getenv("OIDC_JWKS_URL"),
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
else:
|
|
122
|
-
raise ValueError(f"Unsupported auth provider: {provider}")
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
def get_auth_adapter_cached() -> AuthAdapter:
|
|
126
|
-
"""Get the auth adapter instance (no global caching for thread safety)."""
|
|
127
|
-
# Create fresh adapter each time to avoid global state issues
|
|
128
|
-
# The cost of adapter creation is minimal and this ensures thread/test safety
|
|
129
|
-
return get_auth_adapter()
|