Skip to content

Commit a8ccb01

Browse files
committed
Impl: authenticate with HTTP header
- previously done with the help of session cookies - session token is now sent as a HTTP header
1 parent d511e8c commit a8ccb01

File tree

3 files changed

+4
-18
lines changed

3 files changed

+4
-18
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
## [Unreleased]
66
### Added
77

8-
- upgraded support to the latest Coder platform
8+
- upgraded support for the latest Coder REST API
99

1010
### Fixed
1111

12-
- support for the new Coder auth cookies
12+
- authentication flow is now done using HTTP headers
1313

1414
## [2.1.1]
1515

build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ dependencies {
2626
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))
2727
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
2828
implementation("com.squareup.okhttp3:okhttp")
29-
implementation("com.squareup.okhttp3:okhttp-urlconnection")
3029
implementation("com.squareup.okhttp3:logging-interceptor")
3130

3231
implementation("org.zeroturnaround:zt-exec:1.12") {

src/main/kotlin/com/coder/gateway/sdk/CoderRestClientService.kt

+2-15
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@ import com.coder.gateway.sdk.v2.models.WorkspaceTransition
1717
import com.google.gson.Gson
1818
import com.google.gson.GsonBuilder
1919
import com.intellij.openapi.components.Service
20-
import okhttp3.Cookie
21-
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
22-
import okhttp3.JavaNetCookieJar
2320
import okhttp3.OkHttpClient
2421
import okhttp3.logging.HttpLoggingInterceptor
2522
import retrofit2.Retrofit
2623
import retrofit2.converter.gson.GsonConverterFactory
27-
import java.net.CookieManager
2824
import java.net.HttpURLConnection.HTTP_CREATED
2925
import java.net.URL
3026
import java.time.Instant
@@ -43,26 +39,17 @@ class CoderRestClientService {
4339
* @throws [AuthenticationResponseException] if authentication failed.
4440
*/
4541
fun initClientSession(url: URL, token: String): User {
46-
val cookieUrl = url.toHttpUrlOrNull()!!
47-
val cookieJar = JavaNetCookieJar(CookieManager()).apply {
48-
saveFromResponse(
49-
cookieUrl,
50-
listOf(Cookie.parse(cookieUrl, "coder_session_token=$token")!!)
51-
)
52-
}
5342
val gson: Gson = GsonBuilder()
5443
.registerTypeAdapter(Instant::class.java, InstantConverter())
5544
.setPrettyPrinting()
5645
.create()
5746

58-
val interceptor = HttpLoggingInterceptor()
59-
interceptor.setLevel(HttpLoggingInterceptor.Level.BASIC)
6047
retroRestClient = Retrofit.Builder()
6148
.baseUrl(url.toString())
6249
.client(
6350
OkHttpClient.Builder()
64-
.addInterceptor(interceptor)
65-
.cookieJar(cookieJar)
51+
.addInterceptor { it.proceed(it.request().newBuilder().addHeader("Coder-Session-Token", token).build()) }
52+
.addInterceptor(HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BASIC) })
6653
.build()
6754
)
6855
.addConverterFactory(GsonConverterFactory.create(gson))

0 commit comments

Comments
 (0)