Question

I started using django_openid_auth (https://launchpad.net/django-openid-auth) and it works just fine.

I manage to connect to my openid provider and get user authenticated. Thing is that in django_open_auth.views.login_complete there is this block:

if user is not None:
    if user.is_active:
        auth_login(request, user)
        response = HttpResponseRedirect(sanitise_redirect_url(redirect_to))

        # Notify any listeners that we successfully logged in.
        openid_login_complete.send(sender=UserOpenID, request=request,
            openid_response=openid_response)

        return response
    else:
        return render_failure(request, 'Disabled account')

Notice the #notify comment.

I created my own OpenIdBackend subclass of django-openid-auth OpenIDBackend class and put it into core.authentication.openidbackend of my own project

In that file there is: from django_openid_auth.signals import openid_login_complete

def update_request(sender, **kwargs):
    logger.debug('test')

openid_login_complete.connect(update_request)

But that debug line never shows up in log.

So what am i doing wrong? I checked some other django signals threads and one of them said that the import must be exactly the same, otherwise the connection does not appear.

But how can i even debug this? Where is the problem - does the connection never occur cause i put the connect into wrong place or is the problem elsewhere? How can i find this out?

Alan

Edit: I tried everything that was suggested at once and i got it working. I put the signal into separate file, imported it in correct place and also followed the advice given by karthikr (https://stackoverflow.com/users/1628832/karthikr). I also noticed that my logger was not using correct logging conf so everything may have been working earlier, just that logging did not work.

So yeah :). Should not work when you are not feeling well :). Thanks for the help guys.

Was it helpful?

Solution

Where are you coding that signal callback? Are you importing the module where you register the callback before the signal gets sent?

For example, I have used signals and code the in my_app/signals.py. Later, I go to my_app/models.py and add the line:

import my_app.signals

The file where you write your callbacks must be imported before the signals raises:

Where should this code live? You can put signal handling and registration code anywhere you like. However, you’ll need to make sure that the module it’s in gets imported early on so that the signal handling gets registered before any signals need to be sent. This makes your app’s models.py a good place to put registration of signal handlers.

Also you can try to register with the @register decorator. It is pretty much the same but you can try to see if it works the other way:

from django_openid_auth.signals import openid_login_complete
from django.dispatch import receiver

@receiver(openid_login_complete)
def update_request(sender, **kwargs):
    logger.debug('test')

Hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top