self.auth.user always returns NoneType

46 views
Skip to first unread message

Harendra

unread,
Jun 19, 2011, 3:48:44 AM6/19/11
to tipfy
I am using following code to get user info
from tipfy.auth.google import GoogleMixin
from tipfy import RequestHandler
from tipfy import Response
from google.appengine.api import users

class GoogleHandler(RequestHandler,GoogleMixin):
def get(self):
if self.request.args.get('openid.mode', None):
return self.get_authenticated_user(self._on_auth)

return self.authenticate_redirect()

def _on_auth(self, user):
if not user:
abort(403)

# Set the user in the session.
# ...
auth_id = 'google|%s' % user['email']
if not self.auth.user:
print auth_id
user =
self.auth.create_user(username=user['email'],auth_id=auth_id)
print user
return self.redirect('/pretty')

I get following output

google|haren...@gmail.com
None
Status: 302 FOUND
Content-Type: text/html; charset=utf-8
Location: http://localhost:8081/pretty
Content-Length: 262

I need to get username, but I always get None.
Thanks.

Kapil Sachdeva

unread,
Jun 19, 2011, 4:36:36 PM6/19/11
to ti...@googlegroups.com
Try this:


--
You received this message because you are subscribed to the Google Groups "tipfy" group.
To post to this group, send email to ti...@googlegroups.com.
To unsubscribe from this group, send email to tipfy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/tipfy?hl=en.


Harendra

unread,
Jun 19, 2011, 11:24:36 PM6/19/11
to tipfy

Thanks I will give it a go and report back later.

On Jun 20, 5:36 am, Kapil Sachdeva <ksachdev...@gmail.com> wrote:
> Try this:
>
> http://pastebin.com/rLY8D1kj
>
> On Sun, Jun 19, 2011 at 2:48 AM, Harendra <harendra...@gmail.com> wrote:
> > I am using following code to get user info
> > from tipfy.auth.google import GoogleMixin
> > from tipfy import RequestHandler
> > from tipfy import Response
> > from google.appengine.api import users
>
> > class GoogleHandler(RequestHandler,GoogleMixin):
> >    def get(self):
> >        if self.request.args.get('openid.mode', None):
> >            return self.get_authenticated_user(self._on_auth)
>
> >        return self.authenticate_redirect()
>
> >    def _on_auth(self, user):
> >        if not user:
> >            abort(403)
>
> >        # Set the user in the session.
> >        # ...
> >        auth_id = 'google|%s' % user['email']
> >        if not self.auth.user:
> >            print auth_id
> >            user =
> > self.auth.create_user(username=user['email'],auth_id=auth_id)
> >            print user
> >        return self.redirect('/pretty')
>
> > I get following output
>
> > google|harendra...@gmail.com

Harendra

unread,
Jun 20, 2011, 9:46:23 AM6/20/11
to tipfy
Can you provide me with the implementation of MultiAuthStore class
that
you used in the code.
Thanks.

Kapil Sachdeva

unread,
Jun 20, 2011, 10:04:17 AM6/20/11
to ti...@googlegroups.com

from tipfy.auth import MultiAuthStore



MultiAuthStore is part of tipfy

Harendra

unread,
Jun 20, 2011, 9:08:12 PM6/20/11
to tipfy
I see, thanks a lot again.

Harendra

unread,
Jun 26, 2011, 11:23:50 PM6/26/11
to tipfy
In the end this worked,
# -*- coding: utf-8 -*-
from tipfy import RequestHandler
from werkzeug.exceptions import abort
from tipfy.auth.google import GoogleMixin

class GoogleHandler(RequestHandler,GoogleMixin):
def get(self):

'''
url = self.redirect_path()

if self.auth.session:
# User is already signed in, so redirect back.
return self.redirect(url)

self.session['_redirect'] = url
'''

if self.request.args.get('openid.mode', None):
return self.get_authenticated_user(self._on_auth)

return self.authenticate_redirect()

def _on_auth(self, user):
url = "/"
if not user:
self.abort(403)
email = user.pop('email', '')
print "email:"
#print "username:"+username
auth_id = 'google|%s' % email
print "authid"+auth_id+" "+user['name']
#self.auth.login_with_auth_id(auth_id, True)

if not self.auth.user:
user = self.auth.create_user(username=user['name'],
auth_id=auth_id, email=email, type='google')
return self.redirect(url)

username=user['name'] seems the way to get it.

Now I have another problem, suppose if I want to pass username to
another handler how can I do it. This is my likely scenario.
1. User goes to the main page.
2. User clicks "Login" link.
4. Login class has forms and stuff but has no authentication module so
it routes to the GoogleHandler class.
5. Login module receives the user information from GoogleHandler
class.
How can step 5 be accomplished?
Cheers

Harendra

unread,
Jun 27, 2011, 12:38:45 AM6/27/11
to tipfy
I understand this is to be done using Sessions, does anyone have
working code
for using sessions in 1.01b.
Ty.

Harendra

unread,
Jun 27, 2011, 12:55:05 AM6/27/11
to tipfy
This solved the problem
# -*- coding: utf-8 -*-
from tipfy import RequestHandler
from werkzeug.exceptions import abort
from tipfy.auth.google import GoogleMixin
from tipfy.sessions import SessionMiddleware
from tipfy.app import Response

class GoogleHandler(RequestHandler,GoogleMixin):
middleware = [SessionMiddleware()]
def get(self):
if self.request.args.get('openid.mode', None):
return self.get_authenticated_user(self._on_auth)

return self.authenticate_redirect()

def _on_auth(self, user):
url = "response"
if not user:
self.abort(403)
email = user.pop('email', '')
self.session['email']=email;
self.session['username']=user['name']
auth_id = 'google|%s' % email
if not self.auth.user:
user = self.auth.create_user(username=user['name'],
auth_id=auth_id, email=email, type='google')
return self.redirect(url)

class UserRegistrationHandler(RequestHandler,GoogleMixin):
middleware = [SessionMiddleware()]
def get(self):
email=self.session['email']
user=self.session['username']
return Response(email+"\n"+user)

A wonderful link here
http://code.google.com/p/tipfy/source/browse/examples/auth/app/handlers.py

Bert

unread,
Jun 27, 2011, 1:36:33 PM6/27/11
to tipfy
Hi,

How are you dealing with the case where the username is already
taken?


Thanks
Rob
> A wonderful link herehttp://code.google.com/p/tipfy/source/browse/examples/auth/app/handle...

Harendra

unread,
Jun 29, 2011, 2:38:17 AM6/29/11
to tipfy
Hi I am using email as unique identifier so I have not run into such
problem.

Bert

unread,
Jun 29, 2011, 10:14:11 AM6/29/11
to tipfy
Hi Harendra,

Thanks, but just to make sure, does user['name'] return an email
address then?
Because I think the user model sets the user['name'] as the key_name
for the object, and if its not an email address (and isn't unique)
then your user won't be created.

Thanks
Rob

Harendra

unread,
Jun 30, 2011, 1:46:09 AM6/30/11
to tipfy
No the user['name'] does not return email.
email = user.pop('email', '')
does.
I found few interesting things as well,

self.session['firstname']=self.request.args.get('openid.ext1.value.firstname')
#returns first name

self.session['lastname']=self.request.args.get('openid.ext1.value.lastname')
#returns last name
in fact if you print out self.request.args you well get whole bunch of
useful stuff you can use.
Get it add it in cookie and use it.
Ya I am using email as unique identifier but I might run into trouble
in the future.
Do you know of any downfall.
Reply all
Reply to author
Forward
0 new messages