def google_oauth_authorized(resp): access_token = resp['access_token'] refresh_token = resp.get('refresh_token') expires_in = resp['expires_in'] session['google_token'] = (access_token, '') params = { 'access_token': access_token, } me = google.get('userinfo', data=params) user_id = me.data.get('id') user = User.get(user_id=user_id) if not user: first_name = me.data.get('given_name') last_name = me.data.get('family_name') full_name = me.data.get('name') gender = me.data.get('gender') locale = me.data.get('locale') email = me.data.get('email') plus_link = me.data.get('link') avatar_url = me.data.get('picture') user = User(user_id=user_id, first_name=first_name, last_name=last_name, full_name=full_name, gender=gender, locale=locale, email=email, plus_link=plus_link, avatar_url=avatar_url, access_token=access_token, refresh_token=refresh_token, expires_in=expires_in) user.save() else: user.access_token = access_token if refresh_token: user.refresh_token = refresh_token user.expires_in = expires_in user.save() login_user(user)
def token_loader(token): return User.get(auth_token=token)