Git Product home page Git Product logo

django-siwe-auth's People

Contributors

dependabot[bot] avatar jasperalexander avatar payton avatar pconerly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-siwe-auth's Issues

Update GroupManager's is_member to accept a Wallet instance

Currently, GroupManager implementations require the is_member function to accept a string (ethereum_address) as input. This should be replaced with the Wallet user model.

This change will allow users to use the user_passes_test decorator and related mixin. Additionally, users will be able to implement GroupManager instances to take advantage of all core user model attributes along with any project-specific models that are one-to-one with users.

Use browser sessions

Hiya, I don't know much about Django, but I think instead of managing nonces explicitly, they could be incorporated in sessions.

Create tests for Nonce model and logic

Write unit tests for...

  1. nonce_is_valid function
    def _nonce_is_valid(nonce: str) -> bool:
    """
    Check if given nonce exists and has not yet expired.
    :param nonce: The nonce string to validate.
    :return: True if valid else False.
    """
    n = Nonce.objects.get(value=nonce)
    is_valid = False
    if n is not None and n.expiration > datetime.datetime.now(tz=pytz.UTC):
    is_valid = True
    n.delete()
    return is_valid
  2. Nonce model itself
    class Nonce(models.Model):
    value = models.CharField(max_length=24, primary_key=True)
    expiration = models.DateTimeField()
    def __str__(self):
    return self.value
  3. Nonce scrubbing logic (with freezegun?)
    @ratelimit(key='ip', rate='5/m')
    @require_http_methods(["GET"])
    def nonce(request):
    now = datetime.now(tz=pytz.UTC)
    _scrub_nonce()
    n = Nonce(value=secrets.token_hex(12), expiration=now + timedelta(hours=12))
    n.save()
    return JsonResponse({"nonce": n.value})
    def _scrub_nonce():
    # Delete all expired nonce's
    for n in Nonce.objects.filter(expiration__lte=datetime.now(tz=pytz.UTC)):
    n.delete()

examples/notepad/frontend doesn't build

I noticed that when running yarn dev in examples/notepad/frontend it doesn't run, because the ../siwe directory is missing. I also noticed that siwe isn't added to packages.

Is this intentional? I was guessing that you have a local copy of siwe in examples/notepad/siwe.

GroupManager expression layer

Currently, the GroupManager has implementations that go "one layer deep".

  • GroupManager
    • ERC20OwnerManager
    • ERC721OwnerManager
    • ERC1155OwnerManager

These OwnerManager implementations do the following:

  1. Call a contract function
  2. Return true if result is greater than zero

I'd like to build out a second layer that instead takes a lambda as input to generalize step 2. This would then make the hierarchy look something like this:

  • GroupManager
    • ERC20Manager
      • ERC20OwnerManager (> 0)
      • ERC20NewcomerManager (< 10)
    • ERC721Manager
      • ERC721OwnerManager (> 0)
      • ERC721WhaleManager (> 20)
    • ERC1155Manager
      • ERC1155OwnerManager (> 0)

This expression layer won't be advertised. It will allow new users to void any complexities by using the leaf layer while supporting experienced users who want to use all features this app provides.

Provide user the option to log out on the admin login page

When I'm logged in as a non-admin account, I get the message:

Screen Shot 2022-08-15 at 4 35 28 PM

However, the non-admin user doesn't have the option to logout. (I had to manually delete the sessionid cookie in my browser.)

So, we should add the ability to log out on the admin page. I'm surprised that it didn't come along with the login.html form we modified?

Override Admin Login Page

Currently, the Django admin login page defaults to password authentication. This is no longer plausible for key-pair authentication.

Issue identified in #15

Alternative user model that extends Django base user

In an ideal world, we no longer store passwords on the server side.

However, Django is a feature-full framework with plenty of valuable 3rd party applications. Many of these will depend on the base user model.

In order to maximize adoption, we should consider building an alternative user model that extends the base user. This would abstract the username/password fields such that:

username -> ethereum address
password -> non-usable password

This would not be the 'default', but it would be configurable.

Refactor SIWE submodule

SIWE was initially included as a submodule to repurpose the frontend. Since then, we have diverged a lot. It would make more sense to remove the submodule, any backend references, and credit the SIWE repository in the example's README.

This will make the example much more understandable and remove unneeded code while still giving credit to the original repository.

Add custom decorator over GroupManager implementations

Add to the utils package.

Create a customer decorator that allows for initialization of a new GroupManager instance with its own configuration.

Example:

from siwe_auth.custom_groups.erc721 import ERC20OwnerManager

@GroupManagerRestricted(ERC20OwnerManager(config={'contract': '0x1234'}))
def example_restricted_view(request):
    pass

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.