From 72530696663fc815a3754b03740e18bada2ed828 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Mon, 22 Jul 2024 18:29:44 +0200 Subject: [PATCH] Improve insufficient scopes handling in OciRegistryApi --- .../oci/internal/registry/OciRegistryApi.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciRegistryApi.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciRegistryApi.kt index 97fa2aa3..3962bda1 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciRegistryApi.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciRegistryApi.kt @@ -577,15 +577,16 @@ internal class OciRegistryApi(httpClient: HttpClient) { } val registryToken = OciRegistryToken(token) val grantedScopes = registryToken.claims?.scopes - if ((grantedScopes == null) || (grantedScopes == key.scopes)) { - registryToken - } else { - tokenCache.asMap().putIfAbsent( - key.copy(scopes = grantedScopes), - CompletableFuture.completedFuture(registryToken), - ) + if ((grantedScopes != null) && (grantedScopes != key.scopes)) { + if (grantedScopes.isNotEmpty()) { + tokenCache.asMap().putIfAbsent( + key.copy(scopes = grantedScopes), + CompletableFuture.completedFuture(registryToken), + ) + } throw InsufficientScopesException(key.scopes, grantedScopes) } + registryToken } }.map { encodeBearerAuthorization(it.token) } }