From aecb963a82f621e28b698eb6827f3a816b4a5845 Mon Sep 17 00:00:00 2001 From: Zoltan Lux Date: Sun, 9 Jun 2024 16:18:49 +0000 Subject: [PATCH 1/4] add api token auth --- mstrio/api/authentication.py | 31 +++++++++++++++++++++---------- mstrio/connection.py | 3 +++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/mstrio/api/authentication.py b/mstrio/api/authentication.py index 4f44257..eac5e3a 100644 --- a/mstrio/api/authentication.py +++ b/mstrio/api/authentication.py @@ -23,16 +23,27 @@ def login(connection): Complete HTTP response object. """ - return connection.post( - skip_expiration_check=True, - endpoint='/api/auth/login', - data={ - 'username': connection.username, - 'password': connection._Connection__password, - 'loginMode': connection.login_mode, - 'applicationType': 35, - }, - ) + if connection.login_mode == 4096: + return connection.post( + skip_expiration_check=True, + endpoint='/api/auth/login', + data={ + 'username': connection.api_token, + 'loginMode': connection.login_mode, + 'applicationType': 35, + }, + ) + else: + return connection.post( + skip_expiration_check=True, + endpoint='/api/auth/login', + data={ + 'username': connection.username, + 'password': connection._Connection__password, + 'loginMode': connection.login_mode, + 'applicationType': 35, + }, + ) @ErrorHandler(err_msg="Failed to logout.") diff --git a/mstrio/connection.py b/mstrio/connection.py index 27fd6a9..bb445c5 100644 --- a/mstrio/connection.py +++ b/mstrio/connection.py @@ -155,6 +155,7 @@ def __init__( certificate_path: str | None = None, proxies: dict | None = None, identity_token: str | None = None, + api_token: str | None = None, verbose: bool = True, ): """Establish a connection with MicroStrategy REST API. @@ -191,6 +192,7 @@ def __init__( 'http://host.name': 'foo.bar:4012'}) identity_token (str, optional): Identity token for delegated session. Used for connection initialized by GUI. + api_token (str, optional): API token token for the users. verbose (bool, optional): True by default. Controls the amount of feedback from the I-Server. """ @@ -202,6 +204,7 @@ def __init__( self.login_mode = login_mode self.certificate_path = certificate_path self.identity_token = identity_token + self.api_token = api_token self._session = self.__configure_session(ssl_verify, certificate_path, proxies) self._web_version = None self._iserver_version = None From cb250b65ff1701f176a6c0f30955fcc946dbd097 Mon Sep 17 00:00:00 2001 From: Zoltan Lux Date: Sun, 9 Jun 2024 22:10:26 +0000 Subject: [PATCH 2/4] change data to json for api token login --- mstrio/api/authentication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mstrio/api/authentication.py b/mstrio/api/authentication.py index eac5e3a..63cf67a 100644 --- a/mstrio/api/authentication.py +++ b/mstrio/api/authentication.py @@ -27,7 +27,7 @@ def login(connection): return connection.post( skip_expiration_check=True, endpoint='/api/auth/login', - data={ + json={ 'username': connection.api_token, 'loginMode': connection.login_mode, 'applicationType': 35, From 134818beb00decf0602cb3742ca4ab0a1756d75c Mon Sep 17 00:00:00 2001 From: Zoltan Lux Date: Sun, 9 Jun 2024 22:14:16 +0000 Subject: [PATCH 3/4] extend docstring for API token login --- mstrio/connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mstrio/connection.py b/mstrio/connection.py index bb445c5..a64ce15 100644 --- a/mstrio/connection.py +++ b/mstrio/connection.py @@ -181,7 +181,7 @@ def __init__( or Project Name. login_mode (int, optional): Specifies the authentication mode to use. Supported authentication modes are: Standard (1) - (default) or LDAP (16) + (default), LDAP (16) or API token (4096) ssl_verify (bool, optional): If True (default), verifies the server's SSL certificates with each request certificate_path (str, optional): Path to SSL certificate file, if @@ -192,7 +192,7 @@ def __init__( 'http://host.name': 'foo.bar:4012'}) identity_token (str, optional): Identity token for delegated session. Used for connection initialized by GUI. - api_token (str, optional): API token token for the users. + api_token (str, optional): API token token for the users verbose (bool, optional): True by default. Controls the amount of feedback from the I-Server. """ From 7e626441ce5c9637d858bf78ac59aa22e223f44a Mon Sep 17 00:00:00 2001 From: Zoltan Lux Date: Mon, 10 Jun 2024 10:06:19 +0000 Subject: [PATCH 4/4] imporve docstring --- mstrio/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mstrio/connection.py b/mstrio/connection.py index a64ce15..b670346 100644 --- a/mstrio/connection.py +++ b/mstrio/connection.py @@ -192,7 +192,7 @@ def __init__( 'http://host.name': 'foo.bar:4012'}) identity_token (str, optional): Identity token for delegated session. Used for connection initialized by GUI. - api_token (str, optional): API token token for the users + api_token (str, optional): API token token for the user verbose (bool, optional): True by default. Controls the amount of feedback from the I-Server. """