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:
@@ -304,6 +304,7 @@ CapacitorApp.addListener('appUrlOpen', ({ url }) => {
|
|||||||
if (urlObj.hostname === 'authentication') {
|
if (urlObj.hostname === 'authentication') {
|
||||||
const method = urlObj.searchParams.get('method');
|
const method = urlObj.searchParams.get('method');
|
||||||
const payload = JSON.parse(urlObj.searchParams.get('payload') ?? 'false');
|
const payload = JSON.parse(urlObj.searchParams.get('payload') ?? 'false');
|
||||||
|
const serverBaseUrl = urlObj.searchParams.get('server');
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!method ||
|
!method ||
|
||||||
@@ -314,9 +315,20 @@ CapacitorApp.addListener('appUrlOpen', ({ url }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const authService = frameworkProvider
|
let authService = frameworkProvider
|
||||||
.get(DefaultServerService)
|
.get(DefaultServerService)
|
||||||
.server.scope.get(AuthService);
|
.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') {
|
if (method === 'oauth') {
|
||||||
authService
|
authService
|
||||||
.signInOauth(payload.code, payload.state, payload.provider)
|
.signInOauth(payload.code, payload.state, payload.provider)
|
||||||
|
|||||||
Reference in New Issue
Block a user