66from .._execution_context import ExecutionContext
77from .._utils import Endpoint , RequestSpec , infer_bindings
88from ..models import Connection , ConnectionToken , EventArguments
9+ from ..models .connections import ConnectionTokenType
910from ..tracing ._traced import traced
1011from ._base_service import BaseService
1112
@@ -71,7 +72,9 @@ async def retrieve_async(self, key: str) -> Connection:
7172 run_type = "uipath" ,
7273 hide_output = True ,
7374 )
74- def retrieve_token (self , key : str ) -> ConnectionToken :
75+ def retrieve_token (
76+ self , key : str , token_type : ConnectionTokenType = ConnectionTokenType .DIRECT
77+ ) -> ConnectionToken :
7578 """Retrieve an authentication token for a connection.
7679
7780 This method obtains a fresh authentication token that can be used to
@@ -80,12 +83,13 @@ def retrieve_token(self, key: str) -> ConnectionToken:
8083
8184 Args:
8285 key (str): The unique identifier of the connection.
86+ token_type (ConnectionTokenType): The token type to use.
8387
8488 Returns:
8589 ConnectionToken: The authentication token details, including the token
8690 value and any associated metadata.
8791 """
88- spec = self ._retrieve_token_spec (key )
92+ spec = self ._retrieve_token_spec (key , token_type )
8993 response = self .request (spec .method , url = spec .endpoint , params = spec .params )
9094 return ConnectionToken .model_validate (response .json ())
9195
@@ -94,7 +98,9 @@ def retrieve_token(self, key: str) -> ConnectionToken:
9498 run_type = "uipath" ,
9599 hide_output = True ,
96100 )
97- async def retrieve_token_async (self , key : str ) -> ConnectionToken :
101+ async def retrieve_token_async (
102+ self , key : str , token_type : ConnectionTokenType = ConnectionTokenType .DIRECT
103+ ) -> ConnectionToken :
98104 """Asynchronously retrieve an authentication token for a connection.
99105
100106 This method obtains a fresh authentication token that can be used to
@@ -103,12 +109,13 @@ async def retrieve_token_async(self, key: str) -> ConnectionToken:
103109
104110 Args:
105111 key (str): The unique identifier of the connection.
112+ token_type (ConnectionTokenType): The token type to use.
106113
107114 Returns:
108115 ConnectionToken: The authentication token details, including the token
109116 value and any associated metadata.
110117 """
111- spec = self ._retrieve_token_spec (key )
118+ spec = self ._retrieve_token_spec (key , token_type )
112119 response = await self .request_async (
113120 spec .method , url = spec .endpoint , params = spec .params
114121 )
@@ -198,9 +205,11 @@ def _retrieve_spec(self, key: str) -> RequestSpec:
198205 endpoint = Endpoint (f"/connections_/api/v1/Connections/{ key } " ),
199206 )
200207
201- def _retrieve_token_spec (self , key : str ) -> RequestSpec :
208+ def _retrieve_token_spec (
209+ self , key : str , token_type : ConnectionTokenType = ConnectionTokenType .DIRECT
210+ ) -> RequestSpec :
202211 return RequestSpec (
203212 method = "GET" ,
204213 endpoint = Endpoint (f"/connections_/api/v1/Connections/{ key } /token" ),
205- params = {"tokenType" : "direct" },
214+ params = {"tokenType" : token_type . value },
206215 )
0 commit comments