feat(media): chaptarr native OIDC instead of forward_auth
Deploy Caddyfile to valhalla / deploy (push) Successful in 1m23s
Deploy Caddyfile to valhalla / deploy (push) Successful in 1m23s
Chaptarr has built-in OIDC (/signin-oidc), so per the auth standard it gets Pattern A: new homelab-chaptarr OAuth2 provider, old forward_auth proxy provider removed, Caddy block reduced to internal_only + proxy. setup-books-auth.py now handles both OIDC apps generically. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e0240d8e10
commit
f92cad4d66
5 files changed
+72
-48
No files matched your search
+54
-31
@@ -1,8 +1,9 @@
|
||||
# Authentik objects for the books stack (see stacks/media/BOOKS.md).
|
||||
# Idempotent. Run via scripts/run-books-auth.sh (ak shell inside authentik_server).
|
||||
# - forward_single proxy providers for chaptarr / books (CWA) / storyteller,
|
||||
# cloned from homelab-sonarr and attached to the embedded outpost
|
||||
# - native OIDC provider for audiobookshelf (Pattern A)
|
||||
# - forward_single proxy providers for books (CWA) / storyteller, cloned from
|
||||
# homelab-sonarr and attached to the embedded outpost (Pattern B)
|
||||
# - native OIDC providers for chaptarr + audiobookshelf (Pattern A)
|
||||
# Writes the OIDC client ids/secrets to /tmp/books-oidc.env in the container.
|
||||
from authentik.core.models import Application
|
||||
from authentik.crypto.models import CertificateKeyPair
|
||||
from authentik.flows.models import Flow
|
||||
@@ -24,7 +25,6 @@ outpost = Outpost.objects.get(managed="goauthentik.io/outposts/embedded")
|
||||
|
||||
FORWARD = [
|
||||
# (slug, app name, host)
|
||||
("chaptarr", "Chaptarr", "chaptarr.ginnoir.com"),
|
||||
("books", "Calibre-Web Automated", "books.ginnoir.com"),
|
||||
("storyteller", "Storyteller", "storyteller.ginnoir.com"),
|
||||
]
|
||||
@@ -50,31 +50,54 @@ for slug, app_name, host in FORWARD:
|
||||
)
|
||||
print(f"PROXY {slug}: provider pk={p.pk} created={created} app={app.slug}")
|
||||
|
||||
outpost.save() # nudge the embedded outpost to pick up new providers
|
||||
# chaptarr started on forward_auth; it has native OIDC, so drop the proxy provider.
|
||||
old = ProxyProvider.objects.filter(name="homelab-chaptarr").first()
|
||||
if old:
|
||||
outpost.providers.remove(old)
|
||||
old.delete()
|
||||
print("PROXY chaptarr: removed old forward_auth provider")
|
||||
|
||||
abs_host = "audiobooks.ginnoir.com"
|
||||
abs_p, created = OAuth2Provider.objects.get_or_create(
|
||||
name="homelab-audiobooks",
|
||||
defaults=dict(
|
||||
client_type="confidential",
|
||||
authorization_flow=AUTH_FLOW,
|
||||
invalidation_flow=INVALIDATION_FLOW,
|
||||
sub_mode="hashed_user_id",
|
||||
signing_key=SIGNING_KEY,
|
||||
grant_types=["authorization_code", "refresh_token"],
|
||||
_redirect_uris=[
|
||||
{"url": f"https://{abs_host}/auth/openid/callback", "matching_mode": "strict", "redirect_uri_type": "authorization"},
|
||||
{"url": f"https://{abs_host}/auth/openid/mobile-redirect", "matching_mode": "strict", "redirect_uri_type": "authorization"},
|
||||
{"url": "audiobookshelf://oauth", "matching_mode": "strict", "redirect_uri_type": "authorization"},
|
||||
],
|
||||
),
|
||||
)
|
||||
if created:
|
||||
abs_p.property_mappings.set(SCOPES)
|
||||
Application.objects.update_or_create(
|
||||
slug="audiobooks",
|
||||
defaults=dict(name="Audiobookshelf", provider=abs_p, meta_launch_url=f"https://{abs_host}"),
|
||||
)
|
||||
print(f"OIDC audiobooks: provider pk={abs_p.pk} created={created}")
|
||||
with open("/tmp/books-abs-oidc.env", "w") as f:
|
||||
f.write(f"ABS_OIDC_CLIENT_ID={abs_p.client_id}\nABS_OIDC_CLIENT_SECRET={abs_p.client_secret}\n")
|
||||
outpost.save() # nudge the embedded outpost to pick up provider changes
|
||||
|
||||
|
||||
def redirect(url):
|
||||
return {"url": url, "matching_mode": "strict", "redirect_uri_type": "authorization"}
|
||||
|
||||
|
||||
OIDC = [
|
||||
# (slug, app name, host, env prefix, redirect URIs)
|
||||
("chaptarr", "Chaptarr", "chaptarr.ginnoir.com", "CHAPTARR_OIDC", [
|
||||
redirect("https://chaptarr.ginnoir.com/signin-oidc"),
|
||||
]),
|
||||
("audiobooks", "Audiobookshelf", "audiobooks.ginnoir.com", "ABS_OIDC", [
|
||||
redirect("https://audiobooks.ginnoir.com/auth/openid/callback"),
|
||||
redirect("https://audiobooks.ginnoir.com/auth/openid/mobile-redirect"),
|
||||
redirect("audiobookshelf://oauth"),
|
||||
]),
|
||||
]
|
||||
|
||||
lines = []
|
||||
for slug, app_name, host, prefix, uris in OIDC:
|
||||
p, created = OAuth2Provider.objects.get_or_create(
|
||||
name=f"homelab-{slug}",
|
||||
defaults=dict(
|
||||
client_type="confidential",
|
||||
authorization_flow=AUTH_FLOW,
|
||||
invalidation_flow=INVALIDATION_FLOW,
|
||||
sub_mode="hashed_user_id",
|
||||
signing_key=SIGNING_KEY,
|
||||
grant_types=["authorization_code", "refresh_token"],
|
||||
_redirect_uris=uris,
|
||||
),
|
||||
)
|
||||
if created:
|
||||
p.property_mappings.set(SCOPES)
|
||||
Application.objects.update_or_create(
|
||||
slug=slug,
|
||||
defaults=dict(name=app_name, provider=p, meta_launch_url=f"https://{host}"),
|
||||
)
|
||||
print(f"OIDC {slug}: provider pk={p.pk} created={created}")
|
||||
lines += [f"{prefix}_CLIENT_ID={p.client_id}", f"{prefix}_CLIENT_SECRET={p.client_secret}"]
|
||||
|
||||
with open("/tmp/books-oidc.env", "w") as f:
|
||||
f.write("\n".join(lines) + "\n")
|
||||
Reference in new issue
Block a user