<commit_before>import json
from urllib import urlencode
from urlparse import parse_qs, urlunsplit

from flask import redirect, request, url_for
from flaskext.login import LoginManager, login_user
import requests

from makerbase import app
from makerbase.models import User


login_manager = LoginManager()
login_manager.setup_app(app, add_context_processor=True)
login_manager.user_loader(User.get)


@app.route('/signin/github')
def signin_github():
    params = {
        'client_id': app.config['GITHUB_CLIENT_ID'],
        'redirect_url': urlunsplit(('http', 'localhost:5000', url_for('complete_github'), None, None)),
        'scope': '',
    }
    return redirect('https://github.com/login/oauth/authorize?%s' % urlencode(params))


@app.route('/complete/github')
def complete_github():
    try:
        code = request.args.get('code')
    except KeyError:
        raise  # TODO

    params = {
        'client_id': app.config['GITHUB_CLIENT_ID'],
        'client_secret': app.config['GITHUB_SECRET'],
        'code': code,
    }
    token_resp = requests.post('https://github.com/login/oauth/access_token', data=params)
    token_params = parse_qs(token_resp.content)
    access_token = token_params['access_token']<commit_msg>Use real scheme and host when asking github to redirect<commit_after>import json
from urllib import urlencode
from urlparse import parse_qs, urlsplit, urlunsplit

from flask import redirect, request, url_for
from flaskext.login import LoginManager, login_user
import requests

from makerbase import app
from makerbase.models import User


login_manager = LoginManager()
login_manager.setup_app(app, add_context_processor=True)
login_manager.user_loader(User.get)


@app.route('/signin/github')
def signin_github():
    urlparts = urlsplit(request.base_url)
    params = {
        'client_id': app.config['GITHUB_CLIENT_ID'],
        'redirect_url': urlunsplit((urlparts.scheme, urlparts.netloc, url_for('complete_github'), None, None)),
        'scope': '',
    }
    redirect_url = 'https://github.com/login/oauth/authorize?%s' % urlencode(params)
    return redirect(redirect_url)


@app.route('/complete/github')
def complete_github():
    try:
        code = request.args.get('code')
    except KeyError:
        raise  # TODO

    params = {
        'client_id': app.config['GITHUB_CLIENT_ID'],
        'client_secret': app.config['GITHUB_SECRET'],
        'code': code,
    }
    token_resp = requests.post('https://github.com/login/oauth/access_token', data=params)
    token_params = parse_qs(token_resp.content)
    access_token = token_params['access_token']
{'fraction_non_alphanumeric': 0.1218293620292083, 'fraction_numerical': 0.0015372790161414297, 'mean_word_length': 4.247983870967742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7522142', 'n_tokens_mistral': 823, 'n_tokens_neox': 816, 'n_words': 167}