Support native application OAuth callbacks #5

Merged
exler merged 2 commits from feat/native-app-callbacks into main 2026-10-17 23:34:24 +02:00
Collaborator

Summary

Add native application redirect registration, including the exact Immich callback app.immich:///oauth-callback.

  • Central validation permits HTTP(S) URLs with a host, and conservative private-use reverse-domain schemes with absolute paths (com.example.app:/callback and app.immich:///oauth-callback).
  • Reject unsafe schemes, opaque/relative URLs, credentials, fragments, wildcards, native authorities, native query strings, encoded native paths and dot segments.
  • Store the raw registered URI unchanged. Existing exact authorization/token redirect matching, PKCE S256 and client-secret authentication remain unchanged.
  • No DB migration, dependency or feature flag. Existing redirect query construction is preserved (including replacing reserved query keys rather than duplicating them).

Verification

  • TDD: registration failed with 400 before implementation. A separate regression caught duplicate code/state during review before restoring the existing safe query builder.
  • go vet ./...: passes.
  • go test -count=1 ./...: passes (server and totp).
  • In-process handler tests cover admin registration and raw storage, atomic mixed-list rejection, URI safety matrix, complete native authorization-code/token exchange, web callbacks, error redirects, exact-match near misses, missing/plain/wrong PKCE, wrong redirect at token exchange and missing client secret.
  • Native success and error Location preserve the exact app.immich:///oauth-callback prefix.
  • git diff --check origin/main: clean.
  • Race testing unavailable on this Raspberry Pi kernel: ThreadSanitizer fails unsupported VMA range: Found 47 - Supported 48, reproduced in unchanged totp package.
  • Current repository CI triggers only on main/tag push: no pre-merge CI run expected; the local vet/test gates above were actually executed.

Scope and rollout

Supports native redirect targets, not unauthenticated/public OAuth clients. Custom schemes may be claimed by another installed app; S256 and exact matching remain mandatory. Native paths intentionally support a conservative subset (documented in README).

No production deployment or real iOS/Android sign-in was performed. Deploy this Thermopylae change before applying dependent homelab PR exler/homelab#20.

## Summary Add native application redirect registration, including the exact Immich callback `app.immich:///oauth-callback`. - Central validation permits HTTP(S) URLs with a host, and conservative private-use reverse-domain schemes with absolute paths (`com.example.app:/callback` and `app.immich:///oauth-callback`). - Reject unsafe schemes, opaque/relative URLs, credentials, fragments, wildcards, native authorities, native query strings, encoded native paths and dot segments. - Store the raw registered URI unchanged. Existing exact authorization/token redirect matching, PKCE S256 and client-secret authentication remain unchanged. - No DB migration, dependency or feature flag. Existing redirect query construction is preserved (including replacing reserved query keys rather than duplicating them). ## Verification - TDD: registration failed with 400 before implementation. A separate regression caught duplicate `code`/`state` during review before restoring the existing safe query builder. - `go vet ./...`: passes. - `go test -count=1 ./...`: passes (server and totp). - In-process handler tests cover admin registration and raw storage, atomic mixed-list rejection, URI safety matrix, complete native authorization-code/token exchange, web callbacks, error redirects, exact-match near misses, missing/plain/wrong PKCE, wrong redirect at token exchange and missing client secret. - Native success and error `Location` preserve the exact `app.immich:///oauth-callback` prefix. - `git diff --check origin/main`: clean. - Race testing unavailable on this Raspberry Pi kernel: ThreadSanitizer fails `unsupported VMA range: Found 47 - Supported 48`, reproduced in unchanged totp package. - Current repository CI triggers only on main/tag push: no pre-merge CI run expected; the local vet/test gates above were actually executed. ## Scope and rollout Supports native redirect targets, not unauthenticated/public OAuth clients. Custom schemes may be claimed by another installed app; S256 and exact matching remain mandatory. Native paths intentionally support a conservative subset (documented in README). No production deployment or real iOS/Android sign-in was performed. Deploy this Thermopylae change before applying dependent homelab PR https://git.marut.network/exler/homelab/pulls/20.
Validate redirect URIs centrally: http(s) URLs need a host and no
credentials or fragment; native callbacks such as
app.immich:///oauth-callback need a dotted private-use scheme and an
absolute path (RFC 8252 7.1). Registered values are stored and matched
exactly, and authorize appends code/state/error to the raw URI instead
of re-serializing it, so registered queries are kept verbatim.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Restore url.Values query building in authorize
All checks were successful
Push Docker Image / test (push) Successful in 18s
Push Docker Image / push (push) Successful in 50s
773805fc62
Appending code/state to the raw registered URI duplicated them when the
registered query already had code or state, and put them after any
fragment on old registrations. url.Parse/String keeps the native
triple-slash form, so go back to the original q.Set construction and
drop withQuery. The test now checks that a registered tenant param is
kept and that code and state each appear once, with fresh values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
exler merged commit 773805fc62 into main 2026-10-17 23:34:24 +02:00
exler deleted branch feat/native-app-callbacks 2026-10-17 23:34:24 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
exler/thermopylae!5
No description provided.