def get(self): ig_user_id = self.request.get("ig_user_id") if not ig_user_id: self.redirect("/connect") instagram_client = InstagramAPI(**settings.INSTAGRAM_CONFIG) access_token = instagram_client.exchange_user_id_for_access_token( ig_user_id) instagram_client = InstagramAPI(access_token=access_token) user = instagram_client.user("self") profiles = Profile.all() profiles.filter("ig_user_id = ", user.id) profile = (profiles.get() or Profile()) profile.full_name = (user.full_name or user.username) profile.ig_user_id = user.id profile.ig_username = user.username profile.ig_access_token = access_token profile.put() cookieutil = LilCookies(self, settings.COOKIE_SECRET) cookieutil.set_secure_cookie(name="ig_user_id", value=user.id, expires_days=365) self.redirect("/")
def get(self): ig_user_id = self.request.get("ig_user_id") if not ig_user_id: self.redirect("/connect") instagram_client = InstagramAPI(**settings.INSTAGRAM_CONFIG) access_token = instagram_client.exchange_user_id_for_access_token(ig_user_id) instagram_client = InstagramAPI(access_token = access_token) user = instagram_client.user("self") profiles = Profile.all() profiles.filter("ig_user_id = ", user.id) profile = (profiles.get() or Profile()) profile.full_name = (user.full_name or user.username) profile.ig_user_id = user.id profile.ig_username = user.username profile.ig_access_token = access_token profile.put() cookieutil = LilCookies(self, settings.COOKIE_SECRET) cookieutil.set_secure_cookie( name = "ig_user_id", value = user.id, expires_days = 365) self.redirect("/")
class TwitterAuth(webapp.RequestHandler): """Handles Twitter OAuth. See oauth.py for more documentation""" def get(self): self.cookie = LilCookies(self, config.cookie_secret) id = self.cookie.get_secure_cookie("username") if self.request.get("oauth_token"): auth_token = self.request.get("oauth_token") auth_verifier = self.request.get("oauth_verifier") user_info = client.get_user_info(auth_token, auth_verifier=auth_verifier) # Create the user in the database if not id: id = user_info["username"] user = User.all().filter("user ="******"tw" + id) else: user = User.get_by_key_name(id) user.user = user_info["username"] user.name = user_info["name"] user.picture = user_info["picture"] user.token = user_info["token"] user.secret = user_info["secret"] user.put() self.cookie.set_secure_cookie("username", user.key().name()) self.redirect("/") else: self.redirect(client.get_authorization_url())
class FacebookAuth(webapp.RequestHandler): """Handles Facebook OAuth. See http://developers.facebook.com/docs/api""" def get(self): self.cookie = LilCookies(self, config.cookie_secret) id = self.cookie.get_secure_cookie("username") if self.request.get("code"): # Get the access token in exchange for the code url = "https://graph.facebook.com/oauth/access_token?" + urllib.urlencode( { "client_id": config.facebook_params["app_id"], "client_secret": config.facebook_params["app_secret"], "redirect_uri": self.request.url.split("?")[0], "code": self.request.get("code"), } ) out = urlfetch.fetch(url) if out.status_code != 200: self.response.out.write(out.content) return data = cgi.parse_qs(out.content) token = data["access_token"][0] # Get the user profile data out = urlfetch.fetch("https://graph.facebook.com/me?access_token=" + token) if out.status_code != 200: self.response.out.write(out.content) return # Create the user in the database user_info = json.loads(out.content) if not id: id = user_info["id"] user = User.all().filter("fb_id =", id).get() or User(key_name="fb:" + id) else: user = User.get_by_key_name(id) user.name = user_info["name"] user.fb_id = user_info["id"] user.fb_token = token user.put() self.cookie.set_secure_cookie("username", user.key().name()) self.redirect("/") else: url = "https://graph.facebook.com/oauth/authorize?" + urllib.urlencode( { "client_id": config.facebook_params["app_id"], "redirect_uri": self.request.url.split("?")[0], "scope": "publish_stream,offline_access,read_stream", } ) self.redirect(url)
def get(self): auth_token = self.request.get("oauth_token") auth_verifier = self.request.get("oauth_verifier") oauth_client = getOAuth(self.request.host_url) user_info = oauth_client.get_user_info(auth_token, auth_verifier=auth_verifier) username = user_info['username'] d = model.MarkovUserV1(key_name=username) d.atName = username d.pictureUrl = user_info['picture'] d.userSecret = user_info['secret'] d.userToken = user_info['token'] d.name = user_info['name'] self.renderTemplate(cfg.OAUTH_TEMPLATE, USER=username) cookies = LilCookies(self, secrets.cookie_secret) cookies.set_secure_cookie(cfg.COOKIE_USERNAME, username) d.put()