-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KeycloakOpenIDConnection created successfully even if the credentials are wrong #595
Comments
This is a deliberate design of the library, network calls are only made upon executed actions, not during instantiation. |
Hi @ryshoooo, Thanks for your comment! I would expect that, in case there is no network connection to the server, the code would raise the error as soon as possible, and that would be during the instantiation of the class. Also the name of the class is suffixed by "Connection" which is making me believe the connection should already be established during instantiation. Are there any specific reasons on why the library is designed like that? |
Thanks for the feedback :) 1 big reason why is testing, the moment you have network calls being made upon instantiation, the mocking becomes quite painful and on a much higher level than needed in user applications testing. This is particularly true in case the user applications have global instances of Admin/OpenID clients in their applications, i.e. initialized upon import, which makes test structure and mocking quite a bit more painful. Postponing network calls until actual actions are happening makes testing significantly easier. Second reason is a bit more personal I suppose, but I like to have control of when network calls are made, and I do not wish to make them unless absolutely necessary. Instantiation of an object, (again this is my world view, so feel free to disagree) should never make a network call, it should just create an instance of the class ready to be used. If some attributes of the class require network calls to be made, make the attributes lazy and only make the network call when the attribute is retrieved in the user code. I can understand the confusion that a Connection object does not make a connection upon instantiation, but many Connection classes in many popular libraries do not make a network call upon instantiation, only when |
I have the following code
I am using
python-keycloak=4.4.0
This works perfectly and outputs the desired result
However, if I put in some wrong credentials, the
keycloak_connection
object is still created, and thekeycloak.exceptions.KeycloakAuthenticationError: 401: b'{"error":"invalid_grant","error_description":"Invalid user credentials"}'
error is raise only when I call a method from theadmin
object likeadmin.get_server_info()
. Example bellow:This is the output:
I would expect that the error should be raised during the creation of the connection and not afterwards.
Same thing for
client_id
andclient_secret_key
The text was updated successfully, but these errors were encountered: