From 51acb7b12ccdc697bc7d60d3cca0686fa32879d4 Mon Sep 17 00:00:00 2001 From: hkantare Date: Wed, 11 Dec 2024 11:07:13 +0530 Subject: [PATCH] Fix the issue of loading IAM endpoints either for stage or file --- ibm/conns/config.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ibm/conns/config.go b/ibm/conns/config.go index 3931be130da..35b42f053f2 100644 --- a/ibm/conns/config.go +++ b/ibm/conns/config.go @@ -1567,10 +1567,20 @@ func (c *Config) ClientSession() (interface{}, error) { var authenticator core.Authenticator - if c.BluemixAPIKey != "" { - authenticator = &core.IamAuthenticator{ - ApiKey: c.BluemixAPIKey, - URL: EnvFallBack([]string{"IBMCLOUD_IAM_API_ENDPOINT"}, "https://iam.cloud.ibm.com") + "/identity/token", + if c.BluemixAPIKey != "" || sess.BluemixSession.Config.IAMRefreshToken != "" { + if c.BluemixAPIKey != "" { + authenticator = &core.IamAuthenticator{ + ApiKey: c.BluemixAPIKey, + URL: EnvFallBack([]string{"IBMCLOUD_IAM_API_ENDPOINT"}, iamURL), + } + } else { + // Construct the IamAuthenticator with the IAM refresh token. + authenticator = &core.IamAuthenticator{ + RefreshToken: sess.BluemixSession.Config.IAMRefreshToken, + ClientId: "bx", + ClientSecret: "bx", + URL: EnvFallBack([]string{"IBMCLOUD_IAM_API_ENDPOINT"}, iamURL), + } } } else if strings.HasPrefix(sess.BluemixSession.Config.IAMAccessToken, "Bearer") { authenticator = &core.BearerTokenAuthenticator{