1414# See the License for the specific language governing permissions and
1515# limitations under the License.
1616
17- from typing import Any , Dict , Optional
17+ from typing import Dict , Optional
1818
1919from ibm_cloud_sdk_core .token_managers .iam_token_manager import IAMTokenManager
2020
2121from .iam_request_based_token_manager import IAMRequestBasedTokenManager
2222from ..private_helpers import _build_user_agent
2323
2424
25+ # pylint: disable=too-many-instance-attributes
2526class IAMAssumeTokenManager (IAMRequestBasedTokenManager ):
2627 """The IAMAssumeTokenManager takes an api key and information about a trusted profile then performs the necessary
2728 interactions with the IAM token service to obtain and store a suitable bearer token. This token "assumes" the
@@ -84,12 +85,9 @@ def __init__(
8485 ) -> None :
8586 super ().__init__ (
8687 url = url ,
87- client_id = client_id ,
88- client_secret = client_secret ,
8988 disable_ssl_verification = disable_ssl_verification ,
9089 headers = headers ,
9190 proxies = proxies ,
92- scope = scope ,
9391 )
9492
9593 self .iam_profile_id = iam_profile_id
@@ -114,14 +112,6 @@ def __init__(
114112 self .request_payload ['grant_type' ] = 'urn:ibm:params:oauth:grant-type:assume'
115113 self ._set_user_agent (_build_user_agent ('iam-assume-authenticator' ))
116114
117- # Remove unsupported attributes, inherited from the parent class.
118- def __getattribute__ (self , name : str ) -> Any :
119- disallowed_attrs = ['refresh_token' , 'client_id' , 'client_secret' ]
120- if name in disallowed_attrs :
121- raise AttributeError (f"'{ self .__class__ .__name__ } ' has no attribute '{ name } '" )
122-
123- return super ().__getattribute__ (name )
124-
125115 def request_token (self ) -> Dict :
126116 """Retrieves a standard IAM access token by using the IAM token manager
127117 then obtains another access token for the assumed identity.
@@ -140,4 +130,14 @@ def request_token(self) -> Dict:
140130 self .request_payload ['profile_name' ] = self .iam_profile_name
141131 self .request_payload ['account' ] = self .iam_account_id
142132
133+ # Make sure that the unsupported attributes will never be included in the requests.
134+ self .client_id = None
135+ self .client_secret = None
136+ self .scope = None
137+
143138 return super ().request_token ()
139+
140+ def _save_token_info (self , token_response : Dict ) -> None :
141+ super ()._save_token_info (token_response )
142+ # Set refresh token to None unconditionally.
143+ self .refresh_token = None
0 commit comments