Skip to main content

MetaMask Authentication

This is a Django Application which allows you to create one click SignUp and Logins with Meta Mask extension. This application does need a metamask extension installed in your browser to work.

This app using djangorestframework-simplejwt to manage JWT tokens and you can refer to their documentation

Quick start

  1. Add “metaMaskAuth” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'metaMaskAuth',
    ]
  2. Include the metaMaskAuth URLconf in your project urls.py like this:

    path('metamask/', include('metaMaskAuth.urls')),
  3. Run python manage.py migrate to create the metaMask models.

URLS

Create User instance with meta mask wallets public address

  • To create a user and wallet instance based on public address of metamask wallet, send a POST request to the base url for the application. Using the above example it would be metamask/

  • By default the url will expect the following data:

    {
        user: {
            <USER_MODEL_REQUIRED_FIELDS>
    
        }
        public_address: <public_address>
    }
  • Example using the django default user model:

    {
        user: {
            username: Example,
            email: example@gmail.com
        }
        public_address: examplepublicaddress123
    }
  • You dont need to send a password. An unsable password is set for the user model since we wont be needing it for validation

  • An automatic nonce is generated for the user on creation

Retrieve Nonce for Created User

  • To retreive the nonce of an instance send a GET request to the base url for the application with public_address as a path param. Using the above example it would be metamask/<int: public_address>

  • This will fetch the wallet data as per serializer

Login User to get JWT Token

  • To login a user send a POST request to the baseurl + login/<int:public_address> post fix. Using the above example it would be metamask/login/<int: public_address>

  • By default the url will expect the following data:

    {
        signature : <signed by meta mask>
    }
  • This will reqturn an JWT token in reponse which can be used for authentication.

  • The rest is same as using djangorestframework-simplejwt to manage JWT tokens and you can refer to their `documentation <https://django-rest-framework-simplejwt.readthedocs.io/en/latest/>`_ for configurationa and customizations

Settings

You can provide MetaMaskAuth settings like this:

DEFAULTS = {
    "UPDATE_LAST_LOGIN": False,
    "NONCE_LEN": 24,
    "VALIDATION_SERIALIZER": "metaMaskAuth.serializers.WalletTokenObtainSerializer",
    "WALLET_AUTHENTICATION_SERIALIZER": "metaMaskAuth.serializers.WalletAuthSerializer",
    "USE_SLIDING_TOKEN": False,
}
  • UPDATE_LAST_LOGIN

    • A boolean value, which is used to update last login of user on login

  • NONCE_LEN

    • An int value, which controls the length of nonce generated. Default is 24

  • VALIDATION_SERIALIZER

    • This is a string import, for the serializer which contains the logic for validation. You can override this serializer to customize the validation method. This would then be inherited by TokenObtainPairSerializer aswell as TokenObtainSlidingSerializer.

  • USE_SLIDING_TOKEN

    • A boolean value, used to set whether to use sliding token or not.

Metadata

Release files for django-metamask-auth 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-metamask-auth 0.1
File Size Uploaded Provenance Actions
django-metamask-auth-0.1.tar.gz 7.5 kB Without provenance Details for django-metamask-auth-0.1.tar.gz

Release files / django-metamask-auth-0.1.tar.gz

Download URL django-metamask-auth-0.1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9d8719684f47093fde1bc50b51198dc70ff6060a5b586e5794813d8d1ce83e3f
BLAKE2b-256 checksum
How to use checksums
b8db1b40b9684d3c20c128245a796419ffaff0a66e30794c64c53ba63680b9a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Security for django-metamask-auth 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page