On Mon, Feb 20, 2012 at 11:29 PM, Roberto Bouza <bouz...@gmail.com> wrote: > Hello, > > I've been hitting my head pretty hard trying to figure out what the > problem is hope someone here can help. > > I've set up the remote backends and middleware as per the docs and > blatantly I'm coding the META remote_user and nothing happens. like > this: > > MIDDLEWARE_CLASSES = ( > 'django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.auth.middleware.RemoteUserMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware', > )
GOOD: RemoteUserMiddleware will attempt to authenticate as REMOTE_USER if the user has not already been authenticated. > > AUTHENTICATION_BACKENDS = ( > 'django.contrib.auth.backends.RemoteUserBackend', > ) GOOD: RemoteUserBackend will create new users when an unknown user is authenticated. > > Then on my view: > > def login_(request): > request.META['REMOTE_USER'] = 'test123' > try: > user = User.objects.get(username=request.META['REMOTE_USER']) > logger.debug("got user: %s, %s", user.last_name, > user.first_name) > except ObjectDoesNotExist: > logger.debug("username: %s, does not exist", > request.META['REMOTE_USER']) > > return render_to_response('myapp/dashboard.html', > {'section':'dashboard'}, context_instance=RequestContext(request)) > > All goes as planned, but the user is not being created. Am I missing > something here? Yes, wtf are you trying to do here? You cannot randomly change things in request.META from inside your view, and expect the middleware code *that has already run* to create and authenticate as your user. If REMOTE_USER was being set correctly by your web server, what you have configured would work. With it set up correctly, you wouldn't have to mess around looking at request.META['REMOTE_USER'] to get the user, it would be available on request.user. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.