authlib icon indicating copy to clipboard operation
authlib copied to clipboard

Add remove_client method to base_client.registry.BaseOAuth

Open lcdunne opened this issue 2 years ago • 6 comments
trafficstars

What kind of change does this PR introduce? (check at least one)

  • [ x ] Feature

Feature to support removing a client from the oauth instance (see this issue). This works with the Flask client but I am not familiar with the other frameworks enough to set them up to check. As I mentioned in the issue thread it really looks like those other clients inherit from BaseOAuth but please let me know if I'm overlooking something. I'll try to add what is needed.


  • [ x ] You consent that the copyright of your pull request source code belongs to Authlib's author.

lcdunne avatar Sep 23 '23 08:09 lcdunne

Hi, thanks. It would be great if you can add a test case for this method.

lepture avatar Sep 23 '23 13:09 lepture

Sure I'll give that a go. Is there a development build that installs all dependencies needed for testing? And any other information on how you are running the tests?

lcdunne avatar Sep 23 '23 17:09 lcdunne

The whole testing process is automated with tox. Just run tox, and this will create environments for every python version supported, and a few dependency variants, and this will run pytest on those environments.

azmeuk avatar Oct 06 '23 22:10 azmeuk

Can I give a suggestion to change the method name to unregister instead so the naming convention is kept in the same family so to say. Would also suggest the code to be more forgiven for odd behaviors (unlikely with this code but nonetheless a great failsafe).

Code suggestion:

    def unregister(self, name):
        err = None
        if name not in self._registry:
            err = f"Client {name} not found in registry."
        else:
            del self._registry[name]            

        if name not in self._clients:
            err = f"Client {name} not found in clients."
        else:
            del self._clients[name]

        if err:
            raise KeyError(err)

The method create_client first checks if self._clients contains name and if the unregister method do not finish deleting everything, you could end up with a half-deleted state where create_client returns a client that the registry does not have.

andersnauman avatar Nov 03 '23 17:11 andersnauman

Can I give a suggestion to change the method name to unregister instead so the naming convention is kept in the same family so to say.

The register naming is not ideal anyways as it could be confused with registration like defined in OAuth 2.0 Dynamic Client Registration Protocol.

In the long run I think keeping remove_client but move register to add_client would be a better idea.

azmeuk avatar Dec 24 '23 10:12 azmeuk

Also, can you link this PR to that issue ( #583 ), like this?

codespearhead avatar Mar 26 '24 13:03 codespearhead