Giter VIP home page Giter VIP logo

swampdragon-auth's Introduction

Swamp Dragon auth

Installation

pip install swampdragon-auth

Django settings.py file

Add the following code to your settings file:

SWAMP_DRAGON_CONNECTION = ('swampdragon_auth.socketconnection.HttpDataConnection', '/data')

Important note about deployment

If you are running your SwampDragon instances on a subdomain, you need to set

SESSION_COOKIE_DOMAIN = .yourdomain.tld

or the authentication won't be able to access the user.

To access a signed in user in your router:

self.connection.get_user()

or

self.connection.user

Token authentication (thanks to @silentninja)

  1. Add the following to the settings file:

SWAMP_DRAGON_CONNECTION = ('swampdragon_tokenauth.socketconnection.RemoteDataConnection', '/data')

  1. Add the TokenAuthMixin to your router:

from swampdragon_tokenauth.mixins import TokenAuthMixin from swampdragon.route_handler import ModelRouter

TokenAuthMixin should come before the model router

class TodoItemRouter(TokenAuthMixin,ModelRouter):
    route_name = 'todo-item'
    serializer_class = TodoItemSerializer
    model = TodoItem
    permission_classes = [LoginRequired()]

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.filter(todo_list__id=kwargs['list_id'])    

Pass in the drf auth token as 'auth' argument when subscribing to a channel:

In angularjs:

$dragon.onReady(function() {
    $dragon.subscribe('todo-item', $scope.channel, {auth:"your_auth_token"}).then(function(response) {
        // code
    });
    })

Contributing

Contributions are more than welcome, just make sure your pull request works with both python 2.7 and 3.4

swampdragon-auth's People

Contributors

cancan101 avatar mback2k avatar silentninja avatar

Watchers

James Cloos avatar Arne Schauf avatar

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.