From eb953c056563b0562eab3df21f5970baa795f54d Mon Sep 17 00:00:00 2001 From: gogo199432 <9107561+gogo199432@users.noreply.github.com> Date: Thu, 9 Apr 2026 05:30:34 +0200 Subject: [PATCH] fix(android): route OAuth deep link to correct server's AuthService (#14809) Porting over iOS fix for self-hosted SSO to Android from #11563. Fixes #12819 Tested on own instance using Authentik. ## Summary by CodeRabbit * **New Features** * Android authentication now supports an optional server parameter in the callback URL, enabling sign-in against different server instances. * If the specified server cannot be found, the authentication attempt is halted and an error is reported. --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- packages/frontend/apps/android/src/app.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/frontend/apps/android/src/app.tsx b/packages/frontend/apps/android/src/app.tsx index b107e999a..2ea7b2234 100644 --- a/packages/frontend/apps/android/src/app.tsx +++ b/packages/frontend/apps/android/src/app.tsx @@ -304,6 +304,7 @@ CapacitorApp.addListener('appUrlOpen', ({ url }) => { if (urlObj.hostname === 'authentication') { const method = urlObj.searchParams.get('method'); const payload = JSON.parse(urlObj.searchParams.get('payload') ?? 'false'); + const serverBaseUrl = urlObj.searchParams.get('server'); if ( !method || @@ -314,9 +315,20 @@ CapacitorApp.addListener('appUrlOpen', ({ url }) => { return; } - const authService = frameworkProvider + let authService = frameworkProvider .get(DefaultServerService) .server.scope.get(AuthService); + + if (serverBaseUrl) { + const serversService = frameworkProvider.get(ServersService); + const server = serversService.getServerByBaseUrl(serverBaseUrl); + if (!server) { + console.error('Authentication callback server not found', serverBaseUrl); + return; + } + authService = server.scope.get(AuthService); + } + if (method === 'oauth') { authService .signInOauth(payload.code, payload.state, payload.provider)