MasoniteFramework / masonite

The Modern And Developer Centric Python Web Framework. Be sure to read the documentation and join the Discord channel for questions: https://discord.gg/TwKeFahmPZ
http://docs.masoniteproject.com
MIT License
2.22k stars 126 forks source link

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

Open ReS4 opened 3 weeks ago

ReS4 commented 3 weeks ago

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