Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: get_authorize_url #167

Open
fluffybeing opened this issue Sep 21, 2014 · 1 comment
Open

AttributeError: get_authorize_url #167

fluffybeing opened this issue Sep 21, 2014 · 1 comment

Comments

@fluffybeing
Copy link

I am following the facebook exmaple but when I am trying to do the same thing in other app it gives me AttributeError. I have run the facebook example in same virtualenv and its works fine but same is not happening with the other app with also have same env.

from flask import Blueprint, session, render_template, flash, request, redirect, url_for
from flask.ext.login import login_user, logout_user, login_required

from appname import cache
from appname.forms import LoginForm
from appname.models import User
from appname.settings import DevConfig

from rauth.service import OAuth2Service

app_setting = DevConfig()

main = Blueprint('main', __name__)


# login through facebook
graph_url = 'https://graph.facebook.com/'
facebook = OAuth2Service(name='facebook',
                         authorize_url='https://www.facebook.com/dialog/oauth',
                         access_token_url=graph_url + 'oauth/access_token',
                         client_id='(removed for web)',
                         client_secret='(removed for web)',
                         base_url=graph_url)


@main.route('/')
@cache.cached(timeout=1000)
def home():
    return render_template('index.html')


@main.route("/login", methods=["GET", "POST"])
def login():
    form = LoginForm()
    if form.validate_on_submit():

        if login_user(form.user):
            session['user_id'] = form.user.id

            flash("Logged in successfully.", "success")
            return redirect(request.args.get("next") or url_for(".home"))
        else:
            flash("Login failed.", "danger")

    return render_template("login.html", form=form)


@main.route('/facebook')
def facebook():
    redirect_uri = url_for('.authorized', _external=True)
    params = {'redirect_uri': redirect_uri}
    print params
    print dir(facebook)
    return redirect(facebook.get_authorize_url(**params))


@main.route('/authorized')
def authorized():
    # check to make sure the user authorized the request
    if not 'code' in request.args:
        flash('You did not authorize the request')
        return redirect('.index')

    # make a request for the access token credentials using code
    redirect_uri = url_for('authorized', _external=True)
    data = dict(code=request.args['code'], redirect_uri=redirect_uri)

    session = facebook.get_auth_session(data=data)

    # the "me" response
    me = session.get('me').json()

    User.get_or_create(me['username'], me['id'])

    flash('Logged in as ' + me['name'])
    return redirect(url_for('.index'))
Traceback (most recent call last):
  File "/root/.virtualenvs/codemap/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/root/.virtualenvs/codemap/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/root/.virtualenvs/codemap/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/root/.virtualenvs/codemap/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/root/.virtualenvs/codemap/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/root/.virtualenvs/codemap/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/root/.virtualenvs/codemap/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/.virtualenvs/codemap/lib/python2.7/site-packages/flask_debugtoolbar/__init__.py", line 125, in dispatch_request
    return view_func(**req.view_args)
  File "/root/geniuslocale/Flask-Foundation/appname/controllers/main.py", line 54, in facebook
    return redirect(facebook.get_authorize_url(**params))
@maxcountryman
Copy link
Contributor

Can you post the actual error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants