discolabs / django-shopify-auth

A package for adding Shopify authentication to a Django app.
MIT License
144 stars 52 forks source link

Access the Django Admin #63

Open leo9226 opened 3 years ago

leo9226 commented 3 years ago

Is it possible to access the Django Admin as a superuser (independent of any registered Shopify shop/account) and see all configured tables in the Django Admin section?

I am trying to set up the Django Admin as per documentation, but whenever I attempt to access the Admin section (localhost:8000/admin/), it asks me for a Shopify Shop name and password. Even if I type in the correct shop address and password, I cannot gain access.

Has anyone stumbled across this issue and knows what the issue here is or what I am not seeing?

Thanks a lot and stay healthy!

stlk commented 3 years ago

I'm pretty sure there's a way but I don't have any recommendations. We've been using store marked as superuser to get to admin and then switched to auth0 using social-auth-app-django.

stlk commented 9 months ago

So while trying to do this for myself I discovered that you need to use custom user manager.

class UserManager(BaseUserManager):

    def create_user(self, myshopify_domain, password=None):
        """
        Creates and saves a ShopUser with the given domain and password.
        """
        if not myshopify_domain:
            raise ValueError('ShopUsers must have a myshopify domain')

        user = self.model(myshopify_domain=myshopify_domain)

        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, myshopify_domain, password):
        """
        Creates and saves a ShopUser with the given domains and password.
        """
        return self.create_user(myshopify_domain, password)

class AuthAppShopUser(AbstractShopUser, PermissionsMixin):

    objects = UserManager()
    ...
arslandevpy commented 8 months ago

@leo9226 Yes, possible to access the Django Admin as a superuser. Add this code of line in AUTH_USER_MODEL.

USERNAME_FIELD = 'email'

def check_password(self, raw_password):
    return True