# Path: channels/app.py
# def init_database(app):
# def init_disqus(app):
# def init_publisher(app):
# def get_client(key):


import functools
import simplejson
import urllib
import urllib2
from disqusapi import InvalidAccessToken
from flask import url_for, request, redirect, session, render_template
from channels.app import app, disqusapi
    from channels.models import User
        del session['auth']
    return redirect('/')


@app.route('/oauth/authorize/')
def oauth_authorize():
    return redirect('https://disqus.com/api/oauth/2.0/authorize/?%s' % (urllib.urlencode({
        'client_id': disqusapi.public_key,
        'scope': 'read,write',
        'response_type': 'code',
        'redirect_uri': url_for('oauth_callback', _external=True),
    }),))


@app.route('/oauth/error/')
def oauth_error():
    return render_template('/oauth/error.html')


@app.route('/oauth/callback/')
def oauth_callback():

    code = request.args.get('code')
    error = request.args.get('error')
    if error or not code:
        # TODO: show error
        return redirect('/?oauth_error=' + error)

    req = urllib2.Request('https://disqus.com/api/oauth/2.0/access_token/', urllib.urlencode({
        'grant_type': 'authorization_code',

# Path: channels/app.py
# def init_database(app):
# def init_disqus(app):
# def init_publisher(app):
# def get_client(key):


# Path: channels/oauth.py
import functools
import simplejson
import urllib
import urllib2
from disqusapi import InvalidAccessToken
from flask import url_for, request, redirect, session, render_template
from channels.app import app, disqusapi
    from channels.models import User

        del session['auth']
    return redirect('/')


@app.route('/oauth/authorize/')
def oauth_authorize():
    return redirect('https://disqus.com/api/oauth/2.0/authorize/?%s' % (urllib.urlencode({
        'client_id': disqusapi.public_key,
        'scope': 'read,write',
        'response_type': 'code',
        'redirect_uri': url_for('oauth_callback', _external=True),
    }),))


@app.route('/oauth/error/')
def oauth_error():
    return render_template('/oauth/error.html')


@app.route('/oauth/callback/')
def oauth_callback():

    code = request.args.get('code')
    error = request.args.get('error')
    if error or not code:
        # TODO: show error
        return redirect('/?oauth_error=' + error)

    req = urllib2.Request('https://disqus.com/api/oauth/2.0/access_token/', urllib.urlencode({
        'grant_type': 'authorization_code',

        'client_id': disqusapi.public_key,