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.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
gogo199432
2026-04-09 05:30:34 +02:00
committed by GitHub
parent 77c0b2ef47
commit eb953c0565

View File

@@ -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)