@@ -106,7 +106,7 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
106
106
throw IllegalArgumentException (" Query parameter \" $URL \" is missing" )
107
107
}
108
108
109
- val ( client, username) = authenticate(deploymentURL, parameters.token())
109
+ val client = authenticate(deploymentURL, parameters.token())
110
110
111
111
// TODO: If the workspace is missing we could launch the wizard.
112
112
val workspaceName = parameters.workspace() ? : throw IllegalArgumentException (" Query parameter \" $WORKSPACE \" is missing" )
@@ -189,29 +189,35 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
189
189
}
190
190
191
191
/* *
192
- * Return an authenticated Coder CLI and the user's name, asking for the
193
- * token as long as it continues to result in an authentication failure.
192
+ * Return an authenticated Coder CLI, asking for the token as long as it
193
+ * continues to result in an authentication failure and token authentication
194
+ * is required.
194
195
*/
195
- private fun authenticate (deploymentURL : String , queryToken : String? , lastToken : Pair <String , TokenSource >? = null): Pair <CoderRestClient , String > {
196
- // Use the token from the query, unless we already tried that.
197
- val isRetry = lastToken != null
198
- val token = if (! queryToken.isNullOrBlank() && ! isRetry)
199
- Pair (queryToken, TokenSource .QUERY )
200
- else CoderRemoteConnectionHandle .askToken(
201
- deploymentURL.toURL(),
202
- lastToken,
203
- isRetry,
204
- useExisting = true ,
205
- settings,
206
- )
207
- if (token == null ) { // User aborted.
196
+ private fun authenticate (deploymentURL : String , queryToken : String? , lastToken : Pair <String , TokenSource >? = null): CoderRestClient {
197
+ val token = if (settings.requireTokenAuth) {
198
+ // Use the token from the query, unless we already tried that.
199
+ val isRetry = lastToken != null
200
+ if (! queryToken.isNullOrBlank() && ! isRetry)
201
+ Pair (queryToken, TokenSource .QUERY )
202
+ else CoderRemoteConnectionHandle .askToken(
203
+ deploymentURL.toURL(),
204
+ lastToken,
205
+ isRetry,
206
+ useExisting = true ,
207
+ settings)
208
+ } else null
209
+ if (settings.requireTokenAuth && token == null ) { // User aborted.
208
210
throw IllegalArgumentException (" Unable to connect to $deploymentURL , query parameter \" $TOKEN \" is missing" )
209
211
}
210
- val client = CoderRestClientService (deploymentURL.toURL(), token.first)
212
+ val client = CoderRestClientService (deploymentURL.toURL(), token? .first)
211
213
return try {
212
- Pair (client, client.me().username)
214
+ client.authenticate()
215
+ client
213
216
} catch (ex: AuthenticationResponseException ) {
214
- authenticate(deploymentURL, queryToken, token)
217
+ // If doing token auth we can ask and try again.
218
+ if (settings.requireTokenAuth) {
219
+ authenticate(deploymentURL, queryToken, token)
220
+ } else throw ex
215
221
}
216
222
}
217
223
0 commit comments