Skip to content

Commit

Permalink
Add new auth mode: access_token for v12 in AKS
Browse files Browse the repository at this point in the history
Fixes #1154
  • Loading branch information
MariusWirtz committed Oct 23, 2024
1 parent ccb2107 commit 6e42449
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions TM1py/Services/RestService.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AuthenticationMode(Enum):
SERVICE_TO_SERVICE = 6
PA_PROXY = 7
BASIC_API_KEY = 8
ACCESS_TOKEN = 9

@property
def use_v12_auth(self):
Expand Down Expand Up @@ -193,7 +194,8 @@ def _determine_verify(self, verify: [bool, str] = None) -> [bool, str]:
if self._auth_mode in [
AuthenticationMode.IBM_CLOUD_API_KEY,
AuthenticationMode.SERVICE_TO_SERVICE,
AuthenticationMode.BASIC_API_KEY
AuthenticationMode.BASIC_API_KEY,
AuthenticationMode.ACCESS_TOKEN
]:
return True
else:
Expand Down Expand Up @@ -454,7 +456,7 @@ def _construct_service_and_auth_root(self) -> Tuple[str, str]:
elif self._auth_mode is AuthenticationMode.SERVICE_TO_SERVICE:
return self._construct_s2s_service_and_auth_root()

if self._auth_mode is AuthenticationMode.BASIC_API_KEY:
if self._auth_mode in [AuthenticationMode.BASIC_API_KEY, AuthenticationMode.ACCESS_TOKEN]:
return self._construct_all_version_service_and_auth_root_from_base_url()

def _manage_http_adapter(self):
Expand Down Expand Up @@ -700,6 +702,9 @@ def _start_session(self, user: str, password: str, decode_b64: bool = False, nam
access_token = self._generate_ibm_iam_cloud_access_token()
self.add_http_header('Authorization', "Bearer " + access_token)

elif self._auth_mode == AuthenticationMode.ACCESS_TOKEN:
self.add_http_header('Authorization', "Bearer " + self._kwargs.get('access_token'))

# v11 authorization (Basic, CAM) through Headers
else:
token = self._build_authorization_token(
Expand Down Expand Up @@ -1063,6 +1068,8 @@ def _determine_auth_mode(self) -> AuthenticationMode:
]):
if self._kwargs.get('user', None) == 'apikey' and 'planninganalytics.saas.ibm.com' in self._base_url:
return AuthenticationMode.BASIC_API_KEY
elif self._kwargs.get('access_token'):
return AuthenticationMode.ACCESS_TOKEN
return AuthenticationMode.BASIC

if self._kwargs.get('gateway', None):
Expand Down

0 comments on commit 6e42449

Please sign in to comment.