From c0f4bafe7cda7f3d981c068ae395e2995c48280e Mon Sep 17 00:00:00 2001 From: Pauline Date: Thu, 28 Nov 2024 11:40:01 +0000 Subject: [PATCH 1/2] Add support for additional parms for client credentials ktor oauth --- .../kotlin/org/radarbase/ktor/auth/ClientCredentialsConfig.kt | 1 + .../main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt | 3 +++ 2 files changed, 4 insertions(+) diff --git a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/ClientCredentialsConfig.kt b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/ClientCredentialsConfig.kt index b1ba8a72..0f7b8ad2 100644 --- a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/ClientCredentialsConfig.kt +++ b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/ClientCredentialsConfig.kt @@ -6,6 +6,7 @@ data class ClientCredentialsConfig( val tokenUrl: String, val clientId: String? = null, val clientSecret: String? = null, + val additionalParameters: Map? = null, ) { /** * Fill in the client ID and client secret from environment variables. The variables are diff --git a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt index 9a2fd00b..750a2373 100644 --- a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt +++ b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt @@ -56,6 +56,9 @@ fun Auth.clientCredentials( append("grant_type", "client_credentials") append("client_id", authConfig.clientId) append("client_secret", authConfig.clientSecret) + authConfig.additionalParameters?.forEach { (key, value) -> + append(key, value) + } }, ) { accept(ContentType.Application.Json) From f237a9a488670b3a056a07e91fb69d373a1742b6 Mon Sep 17 00:00:00 2001 From: Pauline Date: Thu, 28 Nov 2024 12:07:09 +0000 Subject: [PATCH 2/2] Explicitly specify scope and audience in client credentials config --- .../org/radarbase/ktor/auth/ClientCredentialsConfig.kt | 3 ++- .../kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/ClientCredentialsConfig.kt b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/ClientCredentialsConfig.kt index 0f7b8ad2..17797d92 100644 --- a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/ClientCredentialsConfig.kt +++ b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/ClientCredentialsConfig.kt @@ -6,7 +6,8 @@ data class ClientCredentialsConfig( val tokenUrl: String, val clientId: String? = null, val clientSecret: String? = null, - val additionalParameters: Map? = null, + val scope: String? = null, + val audience: String? = null, ) { /** * Fill in the client ID and client secret from environment variables. The variables are diff --git a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt index 750a2373..18a8e8ad 100644 --- a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt +++ b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt @@ -56,9 +56,8 @@ fun Auth.clientCredentials( append("grant_type", "client_credentials") append("client_id", authConfig.clientId) append("client_secret", authConfig.clientSecret) - authConfig.additionalParameters?.forEach { (key, value) -> - append(key, value) - } + authConfig.scope?.let { append("scope", it) } + authConfig.audience?.let { append("audience", it) } }, ) { accept(ContentType.Application.Json)