Giter VIP home page Giter VIP logo

swampdragon-auth's People

Contributors

asmaps avatar cancan101 avatar mback2k avatar silentninja 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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swampdragon-auth's Issues

AndroidAsync (WebSocket) + SD-Auth

Hi folks,

as part of our project we have an Android App that needs to deal with swampdragon/sockjs-tornado based WebSockets. On client side we use a library called "AndroidAsync" to connect to Websocket.
Therefore we stick to the url shema as described by the SockJS protocol (ws(s)://mydomain:port/data/serverid/session/websocket) , not the raw endpoint.
Connecting and calling a basic route works like a harm. But we got multiple channels which need user based subscription.
Has anyone done it before either on Android or any other mobile operating system?
As far as I know swampdragon-auth makes use of the sessionid provided by django. Usually this is not the way to go with mobile Apps. For example, Django RESTFramework provides Token Auth, which might be THE choice for most of the mobile apps where user data is required.

Is there sth. similar provided by swampdragon(-auth) or better does SockJS actually support Token Auth?
Are there other ways how to send notifications only to a subset of all online users?

Best,
ZuSe

Can't create.

When using my sendMessage() function i keep getting this error:

$scope.sendMessage = function(message) {
    console.log("GETTING SEND MESSAGE FUNCTION");
    $dragon.create('message-route', {message:'test'}).then(function(response) {
        console.log(response);
    }).catch(function(errors) {
        console.log(errors)
    });
}

This is the error I keep getting... I'm very new to angularJS so not really sure what I'm doing wrong.

TypeError: Cannot read property 'send' of null
at Object.5.s.send (swampdragon.min.js:1)
at Object.5.s.sendJSON (swampdragon.min.js:1)
at Object.5.s.callRouter (swampdragon.min.js:1)
at Object.callRouter (services.js:9)
at Object.create (services.js:41)
at k.$scope.sendMessage (controllers.js:28)
at cb.functionCall (angular.js:10795)
at angular.js:19036
at k.$get.k.$eval (angular.js:12632)
at k.$get.k.$apply (angular.js:12730)

SwampDragon + Auth + NGINX => Session Problem

Hi folks,

I have set up an environment related to this guide: http://swampdragon.net/blog/deploying-swampdragon/

I use dev1.mydomain.com (with SSL) for django and dev1sd.mydomain.com (also with SSL) for swampdragon.

swampdragon-auth is installed and highly needed. Connecting to the Websocket with the JavaScript-Client works fine, but when I try to subscribe to a channel I get {signin_required: "you need to sign in"}
returned.
As far as I understand this behaviour is caused by my subdomain setup. I have set
SESSION_COOKIE_DOMAIN = ".mydomain.com" in settings.py, but I still get the error.

On Localhost everything works fine.

I would really appreciate any advice that might help me to solve this issue :)

AttributeError: 'Router' object has no attribute 'user' problem

Hello,

I'm not an experienced developer and i'm having some difficulties with implementing swampdragon-auth into my project.I followed this tutorial http://wildfish.com/blog/2014/12/09/swampdragon-real-time-django-notifications/ and everything works fine. Then i make the changes in the "Additional Notes" part.
Also i added
"swampdragon_auth" in INSTALLED_APPS
and
SWAMP_DRAGON_CONNECTION = ('swampdragon_auth.socketconnection.HttpDataConnection', '/data') into settings file.

When i open the notification URL swampdragon server throws this exception:

Running SwampDragon on 127.0.0.1:9999
ERROR:tornado.general:WebSocket
Traceback (most recent call last):
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/sockjs/tornado/transports/websocket.py", line 60, in on_message
self.session.on_messages(msg)
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/sockjs/tornado/session.py", line 423, in on_messages
self.conn.on_message(msg)
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/swampdragon/connections/sockjs_connection.py", line 79, in on_message
raise e
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/swampdragon/connections/sockjs_connection.py", line 76, in on_message
handler(self).handle(data)
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/swampdragon/route_handler.py", line 62, in handle
m(**kwargs)
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/django/contrib/auth/decorators.py", line 20, in _wrapped_view
if test_func(request.user):
AttributeError: 'NotificationRouter' object has no attribute 'user'
ERROR:tornado.application:Uncaught exception in /data/752/l5won5g4/websocket
Traceback (most recent call last):
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/sockjs/tornado/transports/websocket.py", line 60, in on_message
self.session.on_messages(msg)
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/sockjs/tornado/session.py", line 423, in on_messages
self.conn.on_message(msg)
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/swampdragon/connections/sockjs_connection.py", line 79, in on_message
raise e
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/swampdragon/connections/sockjs_connection.py", line 76, in on_message
handler(self).handle(data)
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/swampdragon/route_handler.py", line 62, in handle
m(**kwargs)
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/django/contrib/auth/decorators.py", line 20, in _wrapped_view
if test_func(request.user):
AttributeError: 'NotificationRouter' object has no attribute 'user'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/tornado/websocket.py", line 402, in _run_callback
callback(_args, *_kwargs)
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/sockjs/tornado/transports/websocket.py", line 70, in on_message
self.abort_connection()
File "/Users/ramapat/Desktop/workspace/Env/lib/python3.4/site-packages/sockjs/tornado/websocket.py", line 28, in abort_connection
self.ws_connection._abort()
AttributeError: 'NoneType' object has no attribute '_abort'

I'm stuck and i don't know what to do. Any help would be highly appreciated.

Configuring user sessions in production continuation of ticket # 14

Hi,
I am having trouble getting this to work in production.
In localhost it works fine because I can set

DRAGON_URL = '152.25.32.123:9000'
SWAMP_DRAGON_HOST = ''152.25.32.123'
SWAMP_DRAGON_PORT = '9000'

However in production I set

DRAGON_URL = 'sd.mydomain.com'
SWAMP_DRAGON_HOST = '127.0.0.1' or SWAMP_DRAGON_HOST = 'myinternalP'
SWAMP_DRAGON_PORT = '9000'
SESSION_COOKIE_DOMAIN = ".mydomain.com

SD works with either configuration. The domains resolve and swampdragon.js config is available,

but sessionid and csrf token are not passed with the session therefore user keeps returning None.

Any suggestions are appreciated...

Can I get the "you need to sign in" message from my custom function?

When user sign out, I test "@login_required" to get some error message.
I use Chrome Developer Tool to check can I get something error message from swampdragon.onChannelMessage or swampdragon.callRouter, but it stop on the setupChannels function in swampdragon.js. and console shows "Uncaught TypeError: Cannot read property 'length' of undefined".
It looks it the setupChannels function in swampdragon.js never check the "signin_required" situation.

session lookup won't work with user_sessions

user_sessions (http://django-user-sessions.readthedocs.org/en/latest/reference.html) is an improved db session management, which unfortunately breaks the init assumption that is made in the HttpDataConnection module (requires an IP and user-agent strings).

Not sure if there is a more generic way of looking up the session from the DB without constructing a new session engine. In the worst case, there would be a second HttpDataConnection class that supports the user_sessions engine.

Not sure if you want to support this out of the box or have it be left to the user an an exercise. For now, I'll probably write my own class to get around this. Let me know if you want me to contribute it back.

User always None (or anonymous)

First thing:
SWAMP_DRAGON_CONNECTION = ('swampdragon_auth.socketconnection.HttpDataConnection', '/data')
this line thorws an error ImportError: No module named 'swampdragon.socketconnection'
But i created a custom connection:
from swampdragon_auth.socketconnection import HttpDataConnection
when i'm logged in to the admin i always get when i debug the connection that the user is None.
and idea why is that?

what i'm trying to do is a chat room that updates the user list on the room so on connection open i want to be able to get a user and and update that list, and when connection close i want to remove that user from the list..
i followed the code that extracts the user from the session and i get an anonymous user.

regular chat works fine..
tnx in advance

get_user returns None

Hello
We have a problem in getting user from self.connection.user, which it does not return user object And the output of "PUBSUB channels" in redis-cli is "(empty list or set)"
Our router code is:

from swampdragon.route_handler import ModelPubRouter
from swampdragon import route_handler
from common.customerdeal.models import CustomerDeal
from common.customerdeal.serializers import CustomerDealSerializer

class CustomerDealRouter(ModelPubRouter):
    route_name = 'deal-route'
    serializer_class = CustomerDealSerializer
    model = CustomerDeal

    def updated(self, obj, **kwargs):
        return

    def deleted(self, obj, obj_id, **kwargs):
        return


    def get_object(self, **kwargs):
        return self.model.objects.get(customer__user=self.connection.user)
    #
    def get_query_set(self, **kwargs):
        return self.model.objects.filter(customer__user = self.connection.user)

    def get_subscription_contexts(self, **kwargs):
        return {'customer__user__pk': self.connection.user.pk}

route_handler.register(CustomerDealRouter)

---------------------------------------------------------- ERROR --------------------------------------------------

ERROR:tornado.general:WebSocket
Traceback (most recent call last):
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/sockjs/tornado/transports/websocket.py", line 60, in on_message
    self.session.on_messages(msg)
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/sockjs/tornado/session.py", line 423, in on_messages
    self.conn.on_message(msg)
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/swampdragon/connections/sockjs_connection.py", line 90, in on_message
    raise e
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/swampdragon/connections/sockjs_connection.py", line 87, in on_message
    handler(self).handle(data)
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/swampdragon/route_handler.py", line 65, in handle
    m(**kwargs)
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/swampdragon/route_handler.py", line 255, in subscribe
    server_channels = make_channels(self.serializer_class, self.include_related, self.get_subscription_contexts(**kwargs))
  File "/Users/vahid/virtualenvs/goldir/goldir/common/customerdeal/routers.py", line 25, in get_subscription_contexts
    return {'customer__user__pk': self.connection.user.pk}
AttributeError: 'NoneType' object has no attribute 'pk'
ERROR:tornado.application:Uncaught exception in /data/300/jzyvqyaf/websocket
Traceback (most recent call last):
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/sockjs/tornado/transports/websocket.py", line 60, in on_message
    self.session.on_messages(msg)
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/sockjs/tornado/session.py", line 423, in on_messages
    self.conn.on_message(msg)
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/swampdragon/connections/sockjs_connection.py", line 90, in on_message
    raise e
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/swampdragon/connections/sockjs_connection.py", line 87, in on_message
    handler(self).handle(data)
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/swampdragon/route_handler.py", line 65, in handle
    m(**kwargs)
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/swampdragon/route_handler.py", line 255, in subscribe
    server_channels = make_channels(self.serializer_class, self.include_related, self.get_subscription_contexts(**kwargs))
  File "/Users/vahid/virtualenvs/goldir/goldir/common/customerdeal/routers.py", line 25, in get_subscription_contexts
    return {'customer__user__pk': self.connection.user.pk}
AttributeError: 'NoneType' object has no attribute 'pk'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/tornado/websocket.py", line 402, in _run_callback
    callback(*args, **kwargs)
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/sockjs/tornado/transports/websocket.py", line 70, in on_message
    self.abort_connection()
  File "/Users/vahid/virtualenvs/goldir/lib/python3.4/site-packages/sockjs/tornado/websocket.py", line 28, in abort_connection
    self.ws_connection._abort()
AttributeError: 'NoneType' object has no attribute '_abort'

Not able to create user specific channels

Hey,

I have been trying to implement user specific real time notifications in a project. While I was able to broadcast the real time notifications, I am facing a stiff struggle to create user specific channels, where selected notifications are sent to user. As far as my attempt for the same goes, following are the pieces of code that I have written after looking at a few examples using swampdragon-auth:

routers.py:

class NotificationRouter(ModelPubRouter):
    valid_verbs = ['subscribe']
    route_name = 'notifications'
    model = Notification
    serializer_class = NotificationSerializer


    def get_query_set(self, **kwargs):
        return self.model.objects.filter(user=self.connection.user)

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

    def get_subscription_contexts(self, **kwargs):
        return {'user__id': self.connection.user.pk}

models.py

class Notification(SelfPublishModel, models.Model):
    serializer_class = NotificationSerializer
    message = models.TextField()
    verb = models.CharField(null=True, default="achieved", max_length=20)
    user = models.ForeignKey(settings.AUTH_USER_MODEL)

and serializer.py

class NotificationSerializer(ModelSerializer):
    class Meta:
        model = 'notifications.Notification'
        publish_fields = ['message','verb','user']

This code does not achieves the user specific notifications execution and broadcasts messages to all users. As far I believe, get_subscription_contexts is the function which filters the notifications to selected users, but I am not able to achieve that with this code. It would be great if anyone could help me resolve this issue.

Thanks
Himanshu

token authentication

Hi Jonas, I am trying to complete your implementation of Token authentication. However, I am having a bit difficulty finding the exact purpose of TokenAuthMixin . I understand it needs to be called during 'subscribe' so that user obj can be retrieved via token, but I am not sure where it needs to be triggered.

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.