refactor(auth, design-system): remove unused methods and annotations for cleanup
- Deleted obsolete methods such as `exchangeAuthorizationCode` and `logout` from the Auth module.
- Removed unused browser PKCE utilities and associated constants.
- Annotated unused components across the Design System with `@Suppress("unused")` for clarity.
- Simplified `LoginViewModel` to handle logout by clearing UI state directly.
This commit is contained in:
+1
-61
@@ -3,19 +3,11 @@ package at.mocode.frontend.core.auth.data
|
||||
import at.mocode.shared.core.AppConstants
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.*
|
||||
import io.ktor.http.*
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Data classes for authentication API communication
|
||||
*/
|
||||
@Serializable
|
||||
data class LoginRequest(
|
||||
val username: String,
|
||||
val password: String
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class LoginResponse(
|
||||
val success: Boolean,
|
||||
@@ -85,49 +77,6 @@ class AuthApiClient(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchange an authorization code (PKCE) for tokens
|
||||
*/
|
||||
suspend fun exchangeAuthorizationCode(code: String, codeVerifier: String, redirectUri: String): LoginResponse {
|
||||
val tokenEndpoint = "$keycloakBaseUrl/realms/$realm/protocol/openid-connect/token"
|
||||
return try {
|
||||
val response = httpClient.submitForm(
|
||||
url = tokenEndpoint,
|
||||
formParameters = Parameters.build {
|
||||
append("grant_type", "authorization_code")
|
||||
append("client_id", clientId)
|
||||
if (!clientSecret.isNullOrBlank()) {
|
||||
append("client_secret", clientSecret)
|
||||
}
|
||||
append("code", code)
|
||||
append("code_verifier", codeVerifier)
|
||||
append("redirect_uri", redirectUri)
|
||||
}
|
||||
) {
|
||||
contentType(ContentType.Application.FormUrlEncoded)
|
||||
}
|
||||
|
||||
if (response.status.isSuccess()) {
|
||||
val kc = response.body<KeycloakTokenResponse>()
|
||||
LoginResponse(
|
||||
success = true,
|
||||
token = kc.access_token,
|
||||
message = null
|
||||
)
|
||||
} else {
|
||||
LoginResponse(
|
||||
success = false,
|
||||
message = "Code-Exchange fehlgeschlagen: HTTP ${'$'}{response.status.value}"
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
LoginResponse(
|
||||
success = false,
|
||||
message = "Code-Exchange Fehler: ${'$'}{e.message}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh authentication token
|
||||
*/
|
||||
@@ -169,15 +118,6 @@ class AuthApiClient(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout and invalidate token
|
||||
*/
|
||||
suspend fun logout(token: String): Boolean {
|
||||
// Empfehlung: Frontend-seitig Token lokal verwerfen.
|
||||
// Optional könnten hier Keycloak-Endpoints für Token-Revocation aufgerufen werden.
|
||||
return true
|
||||
}
|
||||
|
||||
@Serializable
|
||||
private data class KeycloakTokenResponse(
|
||||
val access_token: String,
|
||||
|
||||
+1
@@ -70,6 +70,7 @@ data class AuthState(
|
||||
* to prevent XSS attacks. The token is lost when the browser tab is closed
|
||||
* or refreshed, requiring re-authentication.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
class AuthTokenManager {
|
||||
|
||||
private var currentToken: String? = null
|
||||
|
||||
+4
-11
@@ -46,6 +46,10 @@ class LoginViewModel(
|
||||
_uiState.value = _uiState.value.copy(
|
||||
isAuthenticated = authState.isAuthenticated
|
||||
)
|
||||
// If logged out, clear credentials
|
||||
if (!authState.isAuthenticated) {
|
||||
_uiState.value = LoginUiState()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,15 +133,4 @@ class LoginViewModel(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun logout() {
|
||||
authTokenManager.clearToken()
|
||||
// Reset UI state (clear username/password)
|
||||
_uiState.value = LoginUiState()
|
||||
}
|
||||
|
||||
fun checkAuthenticationStatus() {
|
||||
val isAuthenticated = authTokenManager.hasValidToken()
|
||||
_uiState.value = _uiState.value.copy(isAuthenticated = isAuthenticated)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user