@@ -37,20 +37,31 @@ def __init__(self, cs3_client: CS3Client) -> None:
3737 self ._gateway : GatewayAPIStub = cs3_client ._gateway
3838 self ._log : logging .Logger = cs3_client ._log
3939 self ._config : Config = cs3_client ._config
40- # The user should be able to change the client secret (e.g. token) at runtime
41- self ._client_secret : str | None = None
40+ # The user should be able to change the client secret (e.g. token) and client id at runtime
41+ self ._client_secret : str | None = self ._config .auth_client_secret
42+ self ._client_id : str | None = self ._config .auth_client_id
4243 self ._token : str | None = None
4344
4445 def set_client_secret (self , token : str ) -> None :
4546 """
4647 Sets the client secret, exists so that the user can change the client secret (e.g. token, password) at runtime,
47- without having to create a new Auth object. NOTE that token OR the client secret has to be set when
48- instantiating the client object.
48+ without having to create a new Auth object. Note client secret has to be set when
49+ instantiating the client object or through the configuration .
4950
5051 :param token: Auth token/password.
5152 """
5253 self ._client_secret = token
5354
55+ def set_client_id (self , id : str ) -> None :
56+ """
57+ Sets the client id, exists so that the user can change the client id at runtime, without having to create
58+ a new Auth object. Settings this (either through config or here) is optional unless you are using
59+ basic authentication.
60+
61+ :param token: id.
62+ """
63+ self ._client_id = id
64+
5465 def get_token (self ) -> tuple [str , str ]:
5566 """
5667 Attempts to get a valid authentication token. If the token is not valid, a new token is requested
@@ -72,19 +83,22 @@ def get_token(self) -> tuple[str, str]:
7283 # Token has expired or has not been set, obtain another one.
7384 req = AuthenticateRequest (
7485 type = self ._config .auth_login_type ,
75- client_id = self ._config . auth_client_id ,
86+ client_id = self ._client_id ,
7687 client_secret = self ._client_secret ,
7788 )
7889 # Send the authentication request to the CS3 Gateway
7990 res = self ._gateway .Authenticate (req )
8091
8192 if res .status .code != CODE_OK :
82- self ._log .error (f"Failed to authenticate user { self ._config .auth_client_id } , error: { res .status } " )
93+ self ._log .error (f'msg="Failed to authenticate" '
94+ f'user="{ self ._client_id if self ._client_id else "no_id_set" } " '
95+ f'error_code="{ res .status } "' )
8396 raise AuthenticationException (
84- f"Failed to authenticate user { self ._config .auth_client_id } , error: { res .status } "
97+ f'Failed to authenticate: user="{ self ._client_id if self ._client_id else "no_id_set" } " '
98+ f'error_code="{ res .status } "'
8599 )
86100 self ._token = res .token
87- self ._log .debug (f'msg="Authenticated user" user="{ self ._config . auth_client_id } "' )
101+ self ._log .debug (f'msg="Authenticated user" user="{ self ._client_id if self . _client_id else "no_id_set" } "' )
88102 return ("x-access-token" , self ._token )
89103
90104 def list_auth_providers (self ) -> list [str ]:
@@ -97,7 +111,7 @@ def list_auth_providers(self) -> list[str]:
97111 try :
98112 res = self ._gateway .ListAuthProviders (request = ListAuthProvidersRequest ())
99113 if res .status .code != CODE_OK :
100- self ._log .error (f"List auth providers request failed, error: { res .status } " )
114+ self ._log .error (f'msg= "List auth providers request failed" error_code=" { res .status } "' )
101115 raise Exception (res .status .message )
102116 except grpc .RpcError as e :
103117 self ._log .error ("List auth providers request failed" )
0 commit comments