Skip to content
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

Add remove_client method to base_client.registry.BaseOAuth #585

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions authlib/integrations/base_client/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ def register(self, name, overwrite=False, **kwargs):
self._registry[name] = (overwrite, kwargs)
return self.create_client(name)

def remove_client(self, name):
if name not in self._registry:
raise KeyError(f'Client {name} not found in registry.')

if name not in self._clients:
raise KeyError(f'Client {name} not found in clients.')

del self._registry[name]
del self._clients[name]
Comment on lines +90 to +97
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @lcdunne,

This might be implemented in a bit cleaner and safer way.

Suggested change
if name not in self._registry:
raise KeyError(f'Client {name} not found in registry.')
if name not in self._clients:
raise KeyError(f'Client {name} not found in clients.')
del self._registry[name]
del self._clients[name]
missing = []
if not self._registry.pop(name, None):
missing.append['registry']
if not self._clients.pop(name, None):
missing.append['clients']
if missing:
raise KeyError(f'Client {name} not found in f{" nor ".join(missing)}.')

Best regards!


def generate_client_kwargs(self, name, overwrite, **kwargs):
fetch_token = kwargs.pop('fetch_token', None)
update_token = kwargs.pop('update_token', None)
Expand Down