Skip to content

Commit cd457fd

Browse files
committed
fix(model-client): only use OAuth if explicitly enabled
Otherwise, the client is blocked forever if there is no user doing the login.
1 parent 2dbdbbc commit cd457fd

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientV2.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ abstract class ModelClientV2Builder {
493493
protected var baseUrl: String = "https://localhost/model/v2"
494494
protected var authTokenProvider: (suspend () -> String?)? = null
495495
protected var authRequestBrowser: ((url: String) -> Unit)? = null
496+
protected var oauthEnabled = false
496497
protected var userId: String? = null
497498
protected var connectTimeout: Duration = 1.seconds
498499
protected var requestTimeout: Duration = 30.seconds
@@ -523,9 +524,13 @@ abstract class ModelClientV2Builder {
523524
return this
524525
}
525526

526-
fun authRequestBrowser(browser: ((url: String) -> Unit)?): ModelClientV2Builder {
527+
fun authRequestBrowser(browser: ((url: String) -> Unit)?) = also {
527528
authRequestBrowser = browser
528-
return this
529+
enableOAuth()
530+
}
531+
532+
fun enableOAuth() = also {
533+
oauthEnabled = true
529534
}
530535

531536
fun userId(userId: String?): ModelClientV2Builder {
@@ -580,7 +585,9 @@ abstract class ModelClientV2Builder {
580585
}
581586
}
582587
}
583-
ModelixAuthClient.installAuth(this, baseUrl, authTokenProvider, authRequestBrowser)
588+
if (authTokenProvider != null || oauthEnabled) {
589+
ModelixAuthClient.installAuth(this, baseUrl, authTokenProvider, authRequestBrowser)
590+
}
584591
}
585592
}
586593

mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/AppLevelModelSyncService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class AppLevelModelSyncService() : Disposable {
5050

5151
suspend fun getClient(): IModelClientV2 {
5252
return client.getValue() ?: client.updateValue {
53-
it ?: ModelClientV2.Companion.builder().url(url).build().also { it.init() }
53+
it ?: ModelClientV2.builder().url(url).enableOAuth().build().also { it.init() }
5454
}
5555
}
5656

0 commit comments

Comments
 (0)