def did_come_back(self, values): code = values.get("code") state = values.get("state") redirect_uri = values.get("u") if (self.canary != state) or (not redirect_uri) or (not redirect_uri.startswith("http://gisted.in/")): return False post_url = "https://github.com/login/oauth/access_token" post_data = "client_id={client_id}&client_secret={client_secret}&code={code}&state={state}".format( client_id = conf.credential("github_client_id"), client_secret = conf.credential("github_client_secret"), code = code, state = state) req = urllib2.Request(post_url, post_data, headers={"Accept": "application/json"}) resp = json.load(self.open(req)) self._session["token"] = resp["access_token"] self.redirect_uri = redirect_uri return True
import os import flask import re import gisted.tools as tools import gisted.conf as conf import gisted.session as session import flask as f import jinja2 import logging import urlparse template_dir = os.path.join(os.path.dirname(__file__), "templates") static_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "public") app = flask.Flask(__name__, template_folder = template_dir, static_folder = static_dir) app.secret_key = conf.credential("flask_secret_key") app.session_interface = session.SessionInterface(app.secret_key[:8]) def redirect_index_with_error(error): f.flash(error.message, "error") return f.redirect(f.url_for("index")) def redirect_to_secure(url): urlparse.urlparse(url) return f.redirect(url) def to_gist_id_from_url_if_possible(url): if not url: return None m = re.match("https://gist.github.com/[^/]+/([a-zA-Z0-9]+)", url) if not m:
def make(cls, token=None): return cls(conf.credential("github_client_id"), conf.credential("github_client_secret"), token)
def make(cls, session): return cls(conf.credential("github_client_id"), conf.credential("github_client_secret"), session)
import urllib2 import urlparse import bs4 import gisted.conf as conf def urlopen(req): return urllib.urlopen(req) def random_string(n=8): return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(n)) class Invalid(Exception): def __init__(self, message): super(Invalid, self).__init__(message) FAKE_TOKEN = "fake_token_" + conf.credential("flask_secret_key") TRANSCRIPT_TEMPLSTE = u""" * From: {url} * Through: http://gisted.in/ ---- {title} {title_deco} {body} """ class Post(object):