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

Auth.get_config_options() always return default guard options #837

Open
ReS4 opened this issue Nov 7, 2024 · 0 comments
Open

Auth.get_config_options() always return default guard options #837

ReS4 opened this issue Nov 7, 2024 · 0 comments
Labels

Comments

@ReS4
Copy link

ReS4 commented Nov 7, 2024

Describe the bug

The framework doesn't load related config options when using custom guards for authentication.

Expected behaviour

It should return the options dict instead of the default guard options.

masonite/authentication/Auth.py

...

    def get_config_options(self, guard=None):
        if guard is None:  # Because the guard is always `None`, the default config will load
            options = self.guard_config.get(self.guard_config.get("default"), {})
            options.update(self.options)
            return options

        options = self.guard_config.get(guard, {})
        options.update(self.options)
        return options
...

masonite never passes any argument as guard to get_config_options() !

Steps to reproduce the bug

config > auth.py

GUARDS = {
    "default": "web",
    "web": {"model": User},
    "admin": {"model": Admins},
    "password_reset_table": "password_resets",
    "password_reset_expiration": 1440,  # in minutes. 24 hours. None if disabled
}

CustomAdminGuard.py
almost same as the WebGuard.py

AppProvider.py

...

    def register(self):
        auth = self.application.make("auth")
        ...
        auth.add_guard("admin", CustomAdminGuard(self.application))
...

MyController.py

    ...
    def store(self, request: Request, auth: Auth, response: Response, session: Session):

        if not auth.guard('admin').user(): 
            admin = auth.guard('admin').attempt(request.input("email"), request.input("password"), True)
    ...

Masonite Version

4.20.0

@ReS4 ReS4 added the bug label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant