Weird-Sheep-Labs / django-azure-auth

A simple Django app for user authentication with Azure Active Directory/Entra ID.
MIT License
17 stars 10 forks source link

Disable creation of new accounts setting #12

Closed CaptainPi-PiLabs closed 6 months ago

CaptainPi-PiLabs commented 1 year ago

Extra setting to not allow the creation of new accounts.

Just working on a website where we want it locked down to a few users which we create in the admin portal

Something like ["ALLOW_NEW"] that defaults to true.

Could add it to the AuthHandler.authenticate() in the user does not exist exception.

CaptainPi-PiLabs commented 1 year ago

I should be able to push something in a few days for this

regoawt commented 1 year ago

Hi, yes this sounds like a good feature. Please do go ahead and make a PR!

CaptainPi-PiLabs commented 1 year ago

Access denied to do PR

# ./azure_auth/handlers.py

    def authenticate(self, token: dict) -> UserModel:
        ...

        # Using `UserModel._default_manager.get_by_natural_key` handles custom
        # user model and `USERNAME_FIELD` setting
        try:
            user = UserModel._default_manager.get_by_natural_key(email)
        except UserModel.DoesNotExist:
            if not settings.AZURE_AUTH.get("CREATE_NEW_USER", True):
                return None
            user = UserModel._default_manager.create_user(username=email, email=email)
            user.first_name = attr if (attr := azure_user["givenName"]) else ""
            user.last_name = attr if (attr := azure_user["surname"]) else ""
            user.save()

        return user
# ./README.md

AZURE_AUTH = {
    ...
    "CREATE_NEW_USER": True,    # Optional (Default True) Create new user if user does not exist
}
regoawt commented 1 year ago

Hi,

Can I ask whether you've forked the repo and are submitting a pull request, or are just trying to directly push a change?

I can't see your fork of the repo so I suspect you're just trying to push?

To merge a change, you need to fork the repo and submit a PR from your fork.

Cheers, Armand

CaptainPi-PiLabs commented 1 year ago

Yeah that makes sense. Never done a PR so was relying on GUI a bit. Hit PR, main came up and hit that. Didnt realise i had to make a new fork. Been meaning to learn anyway. I'll give it another go tomorrow then