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

request to fix illogical and redundant code in ResourceProtector (solution provided). #603

Open
danilovmy opened this issue Dec 15, 2023 · 0 comments

Comments

@danilovmy
Copy link

Everywhere in documentation about ResourceProtector, we can find:

from authlib.integrations.django_oauth2 import ResourceProtector, BearerTokenValidator
from django.http import JsonResponse

require_oauth = ResourceProtector()
require_oauth.register_token_validator(BearerTokenValidator(OAuth2Token))

This example with an error (OAuth2Token is not imported) exists in many sources on the internet and probably in many projects. But I don't understand why it cannot be simply organized like this:

require_oauth = ResourceProtector(token_validator=BearerTokenValidator(OAuth2Token))

I don't offer to remove .register_token_validator() method completely, but i am sure: to add posibility to register token_validator on __init__ can reduce on 50% initializing code of ResourceProtector from Authlib in every project!
For example:

class Protector(ResourceProtector):
    def __init__(self, *args, **kwargs):
        validator = kwargs.pop('validator', None)
        super().__init__(*args, **kwargs)
        validator and self.register_token_validator(validator)
@danilovmy danilovmy changed the title request to fix illogical and redundant code in ResourceProtector. Sopution provided. request to fix illogical and redundant code in ResourceProtector (solution provided). Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant