Skip to content

Commit 0160e6f

Browse files
committed
impl: support for certificate based authentication
We now skip token input screen if the user provided a public and a private key for mTLS authentication.
1 parent e02c866 commit 0160e6f

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66

77
- support for matching workspace agent in the URI via the agent name
8+
- support for certificate based authentication
89

910
### Removed
1011

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class CoderRemoteProvider(
244244
environments.value = LoadableState.Value(emptyList())
245245
isInitialized.update { false }
246246
client = null
247-
CoderCliSetupWizardState.resetSteps()
247+
CoderCliSetupWizardState.goToFirstStep()
248248
}
249249

250250
override val svgIcon: SvgIcon =

src/main/kotlin/com/coder/toolbox/sdk/CoderRestClient.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ open class CoderRestClient(
9494
.build()
9595
}
9696

97-
if (token != null) {
97+
if (context.settingsStore.requireTokenAuth) {
98+
if (token.isNullOrBlank()) {
99+
throw IllegalStateException("Token is required for $url deployment")
100+
}
98101
builder = builder.addInterceptor {
99102
it.proceed(
100103
it.request().newBuilder().addHeader("Coder-Session-Token", token).build()

src/main/kotlin/com/coder/toolbox/views/ConnectStep.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ConnectStep(
6767
return
6868
}
6969

70-
if (!CoderCliSetupContext.hasToken()) {
70+
if (context.settingsStore.requireTokenAuth && !CoderCliSetupContext.hasToken()) {
7171
errorField.textState.update { context.i18n.ptrl("Token is required") }
7272
return
7373
}
@@ -77,7 +77,7 @@ class ConnectStep(
7777
val client = CoderRestClient(
7878
context,
7979
CoderCliSetupContext.url!!,
80-
CoderCliSetupContext.token!!,
80+
if (context.settingsStore.requireTokenAuth) CoderCliSetupContext.token else null,
8181
PluginManager.pluginInfo.version,
8282
)
8383
// allows interleaving with the back/cancel action
@@ -91,17 +91,17 @@ class ConnectStep(
9191
statusField.textState.update { (context.i18n.pnotr(progress)) }
9292
}
9393
// We only need to log in if we are using token-based auth.
94-
if (client.token != null) {
94+
if (context.settingsStore.requireTokenAuth) {
9595
statusField.textState.update { (context.i18n.ptrl("Configuring Coder CLI...")) }
9696
// allows interleaving with the back/cancel action
9797
yield()
98-
cli.login(client.token)
98+
cli.login(client.token!!)
9999
}
100100
statusField.textState.update { (context.i18n.ptrl("Successfully configured ${CoderCliSetupContext.url!!.host}...")) }
101101
// allows interleaving with the back/cancel action
102102
yield()
103103
CoderCliSetupContext.reset()
104-
CoderCliSetupWizardState.resetSteps()
104+
CoderCliSetupWizardState.goToFirstStep()
105105
onConnect(client, cli)
106106
} catch (ex: CancellationException) {
107107
if (ex.message != USER_HIT_THE_BACK_BUTTON) {
@@ -127,10 +127,14 @@ class ConnectStep(
127127
} finally {
128128
if (shouldAutoLogin.value) {
129129
CoderCliSetupContext.reset()
130-
CoderCliSetupWizardState.resetSteps()
130+
CoderCliSetupWizardState.goToFirstStep()
131131
context.secrets.rememberMe = false
132132
} else {
133-
CoderCliSetupWizardState.goToPreviousStep()
133+
if (context.settingsStore.requireTokenAuth) {
134+
CoderCliSetupWizardState.goToPreviousStep()
135+
} else {
136+
CoderCliSetupWizardState.goToFirstStep()
137+
}
134138
}
135139
}
136140
}

src/main/kotlin/com/coder/toolbox/views/DeploymentUrlStep.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ class DeploymentUrlStep(
5757
notify("URL is invalid", e)
5858
return false
5959
}
60-
CoderCliSetupWizardState.goToNextStep()
60+
if (context.settingsStore.requireTokenAuth) {
61+
CoderCliSetupWizardState.goToNextStep()
62+
} else {
63+
CoderCliSetupWizardState.goToLastStep()
64+
}
6165
return true
6266
}
6367

src/main/kotlin/com/coder/toolbox/views/state/CoderCliSetupWizardState.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ object CoderCliSetupWizardState {
2525
currentStep = WizardStep.entries.toTypedArray()[(currentStep.ordinal - 1) % WizardStep.entries.size]
2626
}
2727

28-
fun resetSteps() {
28+
fun goToLastStep() {
29+
currentStep = WizardStep.CONNECT
30+
}
31+
32+
fun goToFirstStep() {
2933
currentStep = WizardStep.URL_REQUEST
3034
}
3135
}

0 commit comments

Comments
 (0)