Code Monkey home page Code Monkey logo

django-ip-authn's Introduction

IP based authentication for Django

To install add the middleware to MIDDLEWARE_CLASSES:

'django_ip_authn.authentication.Middleware',

You also need to add the authentication backend to AUTHENTICATION_BACKENDS. This will probably not already exist, in which case you will want the entirety of this:

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'django_ip_authn.authentication.Authenticate',
)

By default it will not authenticate until you also add in the IP numbers that it should allow:

VALID_IP_NUMBERS = [
    '127.0.0.1', '127.0.1.1', # Allow only localhost IP numbers
]

Currently it will automatically allow the user with ID 1, this is the user that you create during the initial database creation in Django.

There is an optional header to determine which request.META header value to use to get the remote IP number. This defaults to REMOTE_ADDR. If you are behind a HTTP router you may need to set this to something like the X-Forwarded-For:

REMOTE_IP_HEADER='HTTP_X_FORWARDED_FOR'

Make sure that your HTTP router always sets this or you will open the possibility for a remote client to get around the IP number check by just setting a header on the request.

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.