Skip to content

Commit

Permalink
Merge pull request #32 from HedvigInsurance/feature/move_network_call…
Browse files Browse the repository at this point in the history
…s_into_authclient

Move network calls into authclient and remove ZignSec option completely
  • Loading branch information
StylianosGakis authored Mar 5, 2024
2 parents e10e343 + 5a1ddba commit 639ae8f
Show file tree
Hide file tree
Showing 37 changed files with 588 additions and 534 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ kotlin {

sourceSets {
commonMain.dependencies {
implementation(libs.ktor.core)
implementation(libs.ktor.json)
implementation(libs.kotlinx.serializationJson)
implementation(libs.ktor.client.contentNegotiation)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.json)
implementation(libs.ktor.client.logging)
}
jvmMain.dependencies {
api(libs.ktor.okhttp)
api(libs.ktor.client.okhttp)
}
iosMain.dependencies {
implementation(libs.ktor.darwin)
implementation(libs.ktor.client.darwin)
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[versions]
kotlin = "1.9.20"
ktor = "2.3.6"
ktor = "2.3.8"
kotlinxSerialization = "1.6.1"
kmmBridge = "0.5.1"
vanniktechMavenPublish = "0.25.3"

[libraries]
ktor-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
ktor-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
kotlinx-serializationJson = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerialization" }
ktor-client-contentNegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
ktor-client-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }

[plugins]
kmmBridge = { id = "co.touchlab.kmmbridge", version.ref = "kmmBridge" }
Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pluginManagement {
google()
gradlePluginPortal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}

Expand Down
24 changes: 9 additions & 15 deletions src/commonMain/kotlin/com/hedvig/authlib/AuthEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ public enum class AuthEnvironment {
}

internal val AuthEnvironment.baseUrl: String
get() {
return when (this) {
AuthEnvironment.STAGING -> "https://auth.dev.hedvigit.com"
AuthEnvironment.PRODUCTION -> "https://auth.prod.hedvigit.com"
}
get() = when (this) {
AuthEnvironment.STAGING -> "https://auth.dev.hedvigit.com"
AuthEnvironment.PRODUCTION -> "https://auth.prod.hedvigit.com"
}

internal val AuthEnvironment.gatewayUrl: String
get() {
return when (this) {
AuthEnvironment.STAGING -> "https://gateway.test.hedvigit.com"
AuthEnvironment.PRODUCTION -> "https://gateway.hedvig.com"
}
get() = when (this) {
AuthEnvironment.STAGING -> "https://gateway.test.hedvigit.com"
AuthEnvironment.PRODUCTION -> "https://gateway.hedvig.com"
}

internal val AuthEnvironment.webBaseUrl: String
get() {
return when (this) {
AuthEnvironment.STAGING -> "https://dev.hedvigit.com"
AuthEnvironment.PRODUCTION -> "https://www.hedvig.com"
}
get() = when (this) {
AuthEnvironment.STAGING -> "https://dev.hedvigit.com"
AuthEnvironment.PRODUCTION -> "https://www.hedvig.com"
}
67 changes: 29 additions & 38 deletions src/commonMain/kotlin/com/hedvig/authlib/AuthRepository.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.hedvig.authlib

import com.hedvig.authlib.url.LoginStatusUrl
import kotlinx.coroutines.flow.Flow
import kotlin.jvm.JvmInline

public interface AuthRepository {
public suspend fun startLoginAttempt(
loginMethod: LoginMethod,
market: String,
market: OtpMarket,
personalNumber: String? = null,
email: String? = null
email: String? = null,
): AuthAttemptResult

public fun observeLoginStatus(statusUrl: StatusUrl): Flow<LoginStatusResult>
public fun observeLoginStatus(statusUrl: LoginStatusUrl): Flow<LoginStatusResult>

public suspend fun loginStatus(statusUrl: StatusUrl): LoginStatusResult
public suspend fun loginStatus(statusUrl: LoginStatusUrl): LoginStatusResult

public suspend fun submitOtp(verifyUrl: String, otp: String): SubmitOtpResult

Expand All @@ -24,47 +24,41 @@ public interface AuthRepository {
public suspend fun revoke(token: String): RevokeResult
}

@Suppress("unused")
public enum class LoginMethod {
SE_BANKID, ZIGNSEC, OTP
SE_BANKID, OTP
}

public enum class OtpMarket {
SE, NO, DK
}

public sealed interface AuthAttemptResult {

public sealed interface Error : AuthAttemptResult {
public data class Localised(val reason: String) : Error
public data class BackendErrorResponse(val message: String, val httpStatusValue: Int) : Error
public data class BackendErrorResponse(val message: String) : Error
public data class IOError(val message: String) : Error
public data class UnknownError(val message: String) : Error
}

public data class BankIdProperties(
val id: String,
val statusUrl: StatusUrl,
val statusUrl: LoginStatusUrl,
val autoStartToken: String,
val liveQrCodeData: String
) : AuthAttemptResult

public data class ZignSecProperties(
val id: String,
val statusUrl: StatusUrl,
val redirectUrl: String
) : AuthAttemptResult

public data class OtpProperties(
val id: String,
val statusUrl: StatusUrl,
val statusUrl: LoginStatusUrl,
val resendUrl: String,
val verifyUrl: String,
val maskedEmail: String?,
) : AuthAttemptResult
}

public data class StatusUrl(val url: String)

public sealed interface AuthTokenResult {
public sealed interface Error: AuthTokenResult {
public data class BackendErrorResponse(val message: String, val httpStatusValue: Int) : Error
public sealed interface Error : AuthTokenResult {
public data class BackendErrorResponse(val message: String) : Error
public data class IOError(val message: String) : Error
public data class UnknownError(val message: String) : Error
}
Expand All @@ -77,8 +71,18 @@ public sealed interface AuthTokenResult {

public sealed interface LoginStatusResult {
public data class Exception(val message: String) : LoginStatusResult
public data class Failed(val message: String) : LoginStatusResult
public data class Pending(val statusMessage: String, val liveQrCodeData: String?) : LoginStatusResult
public data class Failed(val localisedMessage: String) : LoginStatusResult
public data class Pending(
val statusMessage: String,
val bankIdProperties: BankIdProperties?,
) : LoginStatusResult {
public data class BankIdProperties(
val autoStartToken: String,
val liveQrCodeData: String,
val bankIdAppOpened: Boolean,
)
}

public data class Completed(val authorizationCode: AuthorizationCodeGrant) : LoginStatusResult
}

Expand All @@ -102,28 +106,15 @@ public data class RefreshTokenGrant(override val code: String) : Grant

public data class AccessToken(
val token: String,
val expiryInSeconds: Int
val expiryInSeconds: Long
)

public data class RefreshToken(
val token: String,
val expiryInSeconds: Int
val expiryInSeconds: Long
)

public sealed interface RevokeResult {
public data class Error(val message: String) : RevokeResult
public data object Success : RevokeResult
}

public sealed interface MemberAuthorizationCodeResult {
public data class Error(val error: Throwable) : MemberAuthorizationCodeResult

public data class Success(
public val memberPaymentUrl: MemberPaymentUrl,
) : MemberAuthorizationCodeResult
}

@JvmInline
public value class MemberPaymentUrl(
public val url: String
)
Loading

0 comments on commit 639ae8f

Please sign in to comment.