Webapp2 get_by_auth_token using wrong entity key

26 views
Skip to first unread message

Danny Guerrier

unread,
Oct 29, 2014, 9:22:38 PM10/29/14
to web...@googlegroups.com
With webapp2, when creating a new user it just does a simple entity.put() without setting a custom entity key using the auth_id. However if you try to retrieve a user by auth token it assumes there's an entity for (Kind, auth_id) which comes up empty since its key is set to (Kind, id). Am I missing something? Why is that key assumed in get_by_auth_token to be Kind, auth_id?

token_key = cls.token_model.get_key(user_id, 'auth', token)
user_key = model.Key(cls, user_id)

valid_token, user = model.get_multi([token_key, user_key])

http://webapp-improved.appspot.com/_modules/webapp2_extras/appengine/auth/models.html#User.get_by_auth_token

Danny

unread,
Nov 9, 2014, 2:51:40 PM11/9/14
to web...@googlegroups.com
Seems like this isn't getting much activity but just in case someone runs across this bug.

create_user is not setting the key which defaults to setting an id.  I extended the user model and overrode the create_user class method to set an entity key to the auth_id.  You'll need to override add_auth_id to update the key to the new auth_id.

        user_values['auth_ids'] = [auth_id]
        user_key = model.Key(cls, auth_id)
        user = cls(key=user_key, **user_values)
Reply all
Reply to author
Forward
0 new messages