Giter VIP home page Giter VIP logo

django-rest-email-auth's Introduction

django-rest-email-auth

GitHub Workflow Status

Important Links

Project Homepage
https://github.com/cdriehuys/django-rest-email-auth
Documentation
https://django-rest-email-auth.readthedocs.io

Overview

This package provides a simple way to enable authentication with email addresses for a REST API.

Features:
  • Verification of user email addresses
  • Authentication using any of a user's verified email addresses
  • Registration of new users
  • Password resets using verified emails

Compatibility

Python: 3.6 or later
Django: Versions 3.2 through 4.1
Django REST Framework: 3.14 or later

Adding Features

This package was primarily developed for a single project's use. As such it may lack features that other projects require. If that is the case, please open an issue and let us know.

License

This project is licensed under the MIT License.

Authors

Chathan Driehuys ([email protected])

django-rest-email-auth's People

Contributors

cdriehuys avatar dependabot[bot] avatar dqjackso avatar eshaan7 avatar github-actions[bot] avatar mlodic avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

django-rest-email-auth's Issues

Add example project

The example project should show how to use the package. It could also use DRF's documentation generation to describe the package's endpoints.

Add field to track primary email addresses

Each user should have one primary email address. When they add their first email address it should be marked as the primary one. Deletion of the primary address should not be possible.

Use `select_related` to prevent multiple queries in `PasswordResetSerializer`

Inside the save method of PasswordResetSerializer class, the below query is being made atm,

token = models.PasswordResetToken.objects.get(

So on accessing token.email.user, 2 extra DB roundtrips are made.

This can be optimized using select_related to fetch the related EmailAddress and User objects in the first query only.

Code suggestion:

        token = models.PasswordResetToken.objects.select_related("email__user").get(
            key=self.validated_data["key"]
        )

Add endpoint to resend the verification email

Since the email confirmation token can expire, we need an endpoint for re-sending the verification email. If an email that has already been verified is sent to this endpoint, no action should be taken.

Allow registration serializer to be overridden

We should allow the registration serializer to be customized in the app's settings. To make it easier to provide a custom serializer, we should create a base serializer that can be easily extended.

Refactor to avoid exposing email addresses

If we truly want to avoid leaking information about the existence of email addresses we need to refactor the EmailAddress model.

The Problem

Consider the case where a user has already registered the email [email protected]. If another user tries to add that email to their account, we must save a duplicate EmailAddress instance so that we can return its id attribute in the response. Without the id, users could determine the existence of other email addresses by simply seeing if the id field is non-null after attempting to add that address.

The Solution

In order to include the id attribute in the response, we have to actually create a new EmailAddress instance and save it. This will require removing the uniqueness constraint from the email field. We will also have to do our own uniqueness checks when registering a new account and adding an email address for a user.

This also introduces the problem of having EmailAddress instances that can never be verified since they are duplicates. We would then need a management command for clearing out these useless instances.

Setup.py metadata and Django 3 support

In the metadata for this project in setup.py we have the following:

classifiers=[
"Development Status :: 5 - Production/Stable",
# Supported versions of Django
"Framework :: Django",
"Framework :: Django :: 1.11",
"Framework :: Django :: 2.0",
"Framework :: Django :: 2.1",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
# Supported versions of Python
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],

This suggests that there's no support for Django >= v3.0

However the install_requires:

install_requires=[
"Django >= 1.10",
"django-email-utils < 1.0",
"djangorestframework >= 3.0",

Specifies any version of Django that's >= v1.10

Which versions are supported?

Send email verification on signup

When a user registers, an email should be sent to the provided address. If the provided address already exists and is verified, the email should be a notification stating that someone attempted to register with that address. If the email isn't in the system or isn't verified, a verification email should be sent to the address.

Permissions

It would be quite good if you could override the permission_class for the new registration and make it open to everyone (rather than using the settings.ini default).

(Great little project, really having fun using it)

Add authentication backend to handle email addresses

The authentication backend is required for users to be able to authenticate using an email address. We can also alias username to email for the backend which will allow users to sign in using Django's built in authentication system (admin, DRF authentication, etc.).

Dependencies are broken for Django < 2

Newer versions of django-email-utils require Django versions greater than or equal to 2.1. This is causing our builds to fail for older Django versions.

Add developer documentation

Especially with the proposed addition of black in #62, there is a fair amount of setup required to develop the project. This should be documented somewhere.

Fix documentation for installing developer releases

Our development workflow has changed such that there is no longer a develop branch. Development is instead merged straight to master and tags are used to indicate releases. As such, the installation instructions for the bleeding-edge release should use the master branch.

Emit a signal when an email is verified

This would provide a hook for actions that should be performed when an email is performed. To implement this right now you have to add a receiver for the post_save signal and then manually check if the email address is verified.

Django fails system checks

Trying to run any manage.py command that runs Django's system checks produces the following error:

ERRORS:
<class 'rest_email_auth.admin.PasswordResetTokenAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'email__user', which is not a callable, an attribute of 'PasswordResetTokenAdmin', or an attribute or method on 'rest_email_auth.PasswordResetToken'.

Normalize email addresses

Email addresses should be normalized since they are not case sensitive. This also prevents confusion if a user types their email differently sometimes, eg [email protected] and [email protected].

After digging into the RFC for email addresses, only the domain portion of the email is case insensitive.

Another common purpose for normalization is to remove +foo or . from emails attached to providers who deviate from the spec. For example, Gmail ignores . characters, and [email protected] is routed to the same place as [email protected]. However, normalization to this extent is a more specialized problem than this package tries to solve and will not be addressed here.

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.