diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/OpenIDConnectionUtils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/OpenIDConnectionUtils.java index 72fe25c886a..6613cbd4105 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/OpenIDConnectionUtils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/OpenIDConnectionUtils.java @@ -27,6 +27,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.net.ssl.KeyManager; +import javax.net.ssl.TrustManager; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -44,9 +46,6 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; -import javax.net.ssl.KeyManager; -import javax.net.ssl.TrustManager; - /** * Utility class for OpenID token refresh. */ @@ -102,8 +101,10 @@ public static CompletableFuture resolveOIDCTokenFromAuthConfig(Config cu return accessToken; } - // Persist new config and if successful, update the in memory config. try { + //update in memory config + updateInMemoryConfigWithUpdatedToken(currentConfig, map); + //persist kubeConfig persistKubeConfigWithUpdatedToken(currentConfig, map); } catch (IOException e) { LOGGER.warn("oidc: failure while persisting new tokens into KUBECONFIG", e); @@ -115,6 +116,21 @@ public static CompletableFuture resolveOIDCTokenFromAuthConfig(Config cu return CompletableFuture.completedFuture(accessToken); } + /** + * update Updated Access and Refresh token in memory config. + * @param currentConfig config + * @param map updated access and refresh token + */ + private static void updateInMemoryConfigWithUpdatedToken(Config currentConfig, Map map) { + Map authProviderConfig = currentConfig.getAuthProvider().getConfig(); + if (map.containsKey(ID_TOKEN_KUBECONFIG)) { + authProviderConfig.put(ID_TOKEN_KUBECONFIG, String.valueOf(map.get(ID_TOKEN_PARAM))); + } + if (map.containsKey(REFRESH_TOKEN_KUBECONFIG)) { + authProviderConfig.put(REFRESH_TOKEN_KUBECONFIG, String.valueOf(map.get(REFRESH_TOKEN_PARAM))); + } + } + /** * Whether we should try to do token refresh or not, checks whether refresh-token key is set in * HashMap or not