JS-spezifische Module und Dateien entfernt, Multiplattform-Targets korrigiert
Signed-off-by: Stefan Mogeritsch <stefan.mo.co@gmail.com>
This commit is contained in:
-68
@@ -1,68 +0,0 @@
|
||||
package at.mocode.frontend.core.auth.data
|
||||
|
||||
import kotlinx.browser.window
|
||||
|
||||
/**
|
||||
* JS-Implementierung: leitet die gesamte Seite zu Keycloak weiter.
|
||||
* Die Funktion kehrt nicht zurück —
|
||||
* der Callback wird beim nächsten App-Start via [consumePendingOidcCallback] verarbeitet.
|
||||
*/
|
||||
actual suspend fun launchOidcFlow(
|
||||
authUrl: String,
|
||||
callbackPort: Int // wird im Browser ignoriert (kein lokaler Server)
|
||||
): OidcCallbackResult {
|
||||
window.location.href = authUrl
|
||||
// Diese Zeile wird nie erreicht — der Browser leitet weiter
|
||||
return OidcCallbackResult.Redirecting
|
||||
}
|
||||
|
||||
/**
|
||||
* JS-Implementierung: prüft beim App-Start, ob die aktuelle URL einen
|
||||
* OIDC-Callback enthält (code= und state= Parameter von Keycloak).
|
||||
* Bereinigt nach dem Auslesen die URL via replaceState.
|
||||
*/
|
||||
actual fun consumePendingOidcCallback(): OidcCallbackResult? {
|
||||
val search = window.location.search
|
||||
if (!search.contains("code=")) return null
|
||||
|
||||
val params = parseJsQueryParams(search.removePrefix("?"))
|
||||
val code = params["code"] ?: return null
|
||||
val state = params["state"] ?: return null
|
||||
val error = params["error"]
|
||||
|
||||
// URL bereinigen — Code soll nicht im Browser-Verlauf bleiben
|
||||
try {
|
||||
window.history.replaceState(null, "", window.location.pathname)
|
||||
} catch (_: Throwable) {
|
||||
// ignore — kein kritischer Fehler
|
||||
}
|
||||
|
||||
return if (error != null) {
|
||||
OidcCallbackResult.Error(
|
||||
error = error,
|
||||
description = params["error_description"]
|
||||
)
|
||||
} else {
|
||||
OidcCallbackResult.Success(code = code, state = state)
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseJsQueryParams(query: String): Map<String, String> =
|
||||
query.split("&")
|
||||
.filter { it.contains("=") }
|
||||
.associate {
|
||||
val parts = it.split("=", limit = 2)
|
||||
parts[0] to decodeURIComponent(parts.getOrElse(1) { "" })
|
||||
}
|
||||
|
||||
actual fun getOidcRedirectUri(): String {
|
||||
val origin = try {
|
||||
window.location.origin
|
||||
} catch (_: Throwable) {
|
||||
"http://localhost"
|
||||
}
|
||||
return origin + at.mocode.frontend.core.domain.AppConstants.OIDC_REDIRECT_URI_JS_PATH
|
||||
}
|
||||
|
||||
private fun decodeURIComponent(encoded: String): String =
|
||||
js("decodeURIComponent(encoded)").unsafeCast<String>()
|
||||
Reference in New Issue
Block a user