0

For some reason I keep getting 404 when I am redirected by my application after logging in if I have a permission attached to that view but everything is fine if I remove the permission. I am using an AuthTktAuthenticationPolicy and I have already tried adding the following callback:

def principalFinder(username, request):
    return [Authenticated]

but that didn't change anything. This is the view in question:

@view_config(route_name='test', context=myAERO, permission='editAln')
def test(request):
    return Response(request.authenticated_userid)

as you can see it uses the class myAERO as its context:

class myAERO():
    __acl__ = [
    (Allow, Authenticated, 'editAln')
    ]
    def __init__(self, request):
        self.request = request

Now, it seems that there is nothing wrong with the authentication because if I remove permission='editAln' from the @view_config() decorator, my app does show return the username I used to log in.

I am absolutely puzzled by this. I could understand getting a 403 forbidden, but I just don't understand why I keep getting a 404 status code at all! I found this question that seems to be somewhat related, but as you can see I am not using the name attribute at all, so it didn't really help me. This is my first time using Pyramid and in my mind what I am trying to accomplish with my application (responding to XHR POST requests with JSON responses based on the username of the authenticated user) should not be that hard, so I am hoping that someone with slightly more Pyramid experience can help me understand this.

Superpelican
  • 85
  • 1
  • 8

1 Answers1

0

I solved the problem by setting the myAERO class as the root factory instead of setting it as the context for each individual view. I got the idea from Michael Merickel's auth demo. Frankly I have no idea why this works, so a comment explaining why would still be much appreciated.

EDIT: After doing some more reading, it seems to me that it somehow related to the whole URL Dispatch vs Traversal thing, which I am still trying to grasp at the moment.

Superpelican
  • 85
  • 1
  • 8