librelist archives

« back to archive

Unable to add user through Facebook login

Unable to add user through Facebook login

From:
Kundan Singh
Date:
2013-05-25 @ 11:31
Hello,
In my app i'm having a fblogin method for letting user login through
facebook.

The complete logic is:


@app.route('/fblogin')
def fblogin():
    return facebook.authorize(callback=url_for('facebook_authorized',
        next=request.args.get('next') or request.referrer or None,
        _external=True))

@app.route('/login/authorized')
@facebook.authorized_handler
def facebook_authorized(resp):
    next_url = request.args.get('next') or url_for('index')
    if resp is None:
        flash('You denied the login')
        return redirect(next_url)

    session['fb_access_token'] = (resp['access_token'], '')

    me = facebook.get('/me')
    user = Users.query.filter_by(fb_id=me.data['id']).first()

    if user is None:
      fb_id = me.data['id']

      if me.data['username']:
        fb_username = me.data['username']
      else:
        fb_username = me.data['name']

      fb_email = me.data['email']

      role = 5
      user = Users(fb_username, 'temp',fb_email, role)
      user.fb_id = me.data['id']
      user.activate  = True
      user.created = datetime.utcnow()
      db.session.add(user)
      db.session.commit()
    session['user_id'] = user.uid

    flash('You are now logged in as %s' % user.username)
    return redirect(url_for('index'))


@facebook.tokengetter
def get_facebook_oauth_token():
    return session.get('fb_access_token')


When i use this method in localhost:5000 it works fine.

Now i deployed this code on mywebsite.com and when i try to login using
facebook, it asks for permission and when click *Okay* it comes back and A
error 500 page is served with url in browser being:


http://www.mywebsite.com/login/authorized?next=http%3A%2F%2Fwww.backmunch.com%2F&code=AQDed70eh7mGRuNleJqDSzdfasfdsafeewfasdfadfdsafadfasdfaf3xZCVAXvnHRnw-Q4G2s3Wf2q57kYHXWfddfadscadf2dfs2sdfvvdJeWgLVUiQozqJ8ExLSmbawUal__WJ_gMmaWxAejcgrCiB0neHvGyt4kHh-8-UQ55tg-9nmiIYg-dF89zkW3ROHUmJI476TM7H4lJJXAaM9fANN3u2eWeoEFIwWqRxpt3EEd8QlWGzbFaLPrAwsaqwNNSUSX7f9TUxFSnMk9RigeF6I#_=_<http://www.backmunch.com/login/authorized?next=http%3A%2F%2Fwww.backmunch.com%2F&code=AQDed70eh7mGRuNleJqDSzmbduKFFC7NyzAuO5b0QGRCrC2xiNlV-JeCPgQx2-Jdj5jr0nlOlw9Ksmcya4bJIs-sNrXYi3f3xZCVAXvnHRnw-Q4G2s3Wf2q57kYHXWNkrO6hWTmZWP3BvV4mUTvvdJeWgLVUiQozqJ8ExLSmbawUal__WJ_gMmaWxAejcgrCiB0neHvGyt4kHh-8-UQ55tg-9nmiIYg-dF89zkW3ROHUmJI476TM7H4lJJXAaM9fANN3u2eWeoEFIwWqRxpt3EEd8QlWGzbFaLPrAwsaqwNNSUSX7f9TUxFSnMk9RigeF6I#_=_>

On locahost it was successfully coming to http://www.mywebsite.com/#_=_ but
not in deployed case.

Since mysite's log says:

[Sat May 25 11:25:32 2013] GET /fblogin => generated 605 bytes in 3 msecs
(HTTP/1.1 302) 4 headers in 566 bytes (1 switches on core 0)
[pid: 11797|app: 0|req: 73/73] 116.202.84.0 () {40 vars in 1652 bytes}

[Sat May 25 11:25:36 2013] GET /login/authorized?next=http%3A%2F%
2Fwww.backmunch.com

%2F&code=AQB1-7Fdd7xRwqWv5uEQLiHxbUikaOKRoDS1FNBNTnbNSiK5s4dcFhQw-m_H7eFG6Rh25GiIzP6gwxrXLZV0zeSLDLg0MplDUjDMZR4PGpQc-Wr3Dq5lvivEv7a_vHy3abLTnkD7zGjCAGsBXApFsT-Lr81m9BBVkjiP5kX76Nv7SNugy9ynvl3bdWHleU-X3aqboGeUMrsyOk9wdgQgVU7HzXsFQ8AS6tPYAKGFuyJApoGiaC1pve3YnEa3mVUROjoie_j-CcDRk0tb3JBsmX4d88hKJH9985WpT7AWGfmETfkTxAKXe4hdsqzHJ6lSvZA
 => generated 3065 bytes in 792 msecs (HTTP/1.1 500) 2 headers in 100 bytes
(1 switches on core 0)


What is the reason? Please suggest

Re: [flask] Unable to add user through Facebook login

From:
Adam Patterson
Date:
2013-05-25 @ 18:59
Do you have app.debug = True ?

You would get more information about the 500 error.


On Sat, May 25, 2013 at 4:31 AM, Kundan Singh <ksingh.pilani@gmail.com>wrote:

> Hello,
> In my app i'm having a fblogin method for letting user login through
> facebook.
>
> The complete logic is:
>
>
> @app.route('/fblogin')
> def fblogin():
>     return facebook.authorize(callback=url_for('facebook_authorized',
>         next=request.args.get('next') or request.referrer or None,
>         _external=True))
>
> @app.route('/login/authorized')
> @facebook.authorized_handler
> def facebook_authorized(resp):
>     next_url = request.args.get('next') or url_for('index')
>     if resp is None:
>         flash('You denied the login')
>         return redirect(next_url)
>
>     session['fb_access_token'] = (resp['access_token'], '')
>
>     me = facebook.get('/me')
>     user = Users.query.filter_by(fb_id=me.data['id']).first()
>
>     if user is None:
>       fb_id = me.data['id']
>
>       if me.data['username']:
>         fb_username = me.data['username']
>       else:
>         fb_username = me.data['name']
>
>       fb_email = me.data['email']
>
>       role = 5
>       user = Users(fb_username, 'temp',fb_email, role)
>       user.fb_id = me.data['id']
>       user.activate  = True
>       user.created = datetime.utcnow()
>       db.session.add(user)
>       db.session.commit()
>     session['user_id'] = user.uid
>
>     flash('You are now logged in as %s' % user.username)
>     return redirect(url_for('index'))
>
>
> @facebook.tokengetter
> def get_facebook_oauth_token():
>     return session.get('fb_access_token')
>
>
> When i use this method in localhost:5000 it works fine.
>
> Now i deployed this code on mywebsite.com and when i try to login using
> facebook, it asks for permission and when click *Okay* it comes back and
> A error 500 page is served with url in browser being:
>
>
> 
http://www.mywebsite.com/login/authorized?next=http%3A%2F%2Fwww.backmunch.com%2F&code=AQDed70eh7mGRuNleJqDSzdfasfdsafeewfasdfadfdsafadfasdfaf3xZCVAXvnHRnw-Q4G2s3Wf2q57kYHXWfddfadscadf2dfs2sdfvvdJeWgLVUiQozqJ8ExLSmbawUal__WJ_gMmaWxAejcgrCiB0neHvGyt4kHh-8-UQ55tg-9nmiIYg-dF89zkW3ROHUmJI476TM7H4lJJXAaM9fANN3u2eWeoEFIwWqRxpt3EEd8QlWGzbFaLPrAwsaqwNNSUSX7f9TUxFSnMk9RigeF6I#_=_<http://www.backmunch.com/login/authorized?next=http%3A%2F%2Fwww.backmunch.com%2F&code=AQDed70eh7mGRuNleJqDSzmbduKFFC7NyzAuO5b0QGRCrC2xiNlV-JeCPgQx2-Jdj5jr0nlOlw9Ksmcya4bJIs-sNrXYi3f3xZCVAXvnHRnw-Q4G2s3Wf2q57kYHXWNkrO6hWTmZWP3BvV4mUTvvdJeWgLVUiQozqJ8ExLSmbawUal__WJ_gMmaWxAejcgrCiB0neHvGyt4kHh-8-UQ55tg-9nmiIYg-dF89zkW3ROHUmJI476TM7H4lJJXAaM9fANN3u2eWeoEFIwWqRxpt3EEd8QlWGzbFaLPrAwsaqwNNSUSX7f9TUxFSnMk9RigeF6I#_=_>
>
> On locahost it was successfully coming to 
http://www.mywebsite.com/#_=_but not in deployed case.
>
> Since mysite's log says:
>
> [Sat May 25 11:25:32 2013] GET /fblogin => generated 605 bytes in 3 msecs
> (HTTP/1.1 302) 4 headers in 566 bytes (1 switches on core 0)
> [pid: 11797|app: 0|req: 73/73] 116.202.84.0 () {40 vars in 1652 bytes}
>
> [Sat May 25 11:25:36 2013] GET /login/authorized?next=http%3A%2F%
> 2Fwww.backmunch.com
> 
%2F&code=AQB1-7Fdd7xRwqWv5uEQLiHxbUikaOKRoDS1FNBNTnbNSiK5s4dcFhQw-m_H7eFG6Rh25GiIzP6gwxrXLZV0zeSLDLg0MplDUjDMZR4PGpQc-Wr3Dq5lvivEv7a_vHy3abLTnkD7zGjCAGsBXApFsT-Lr81m9BBVkjiP5kX76Nv7SNugy9ynvl3bdWHleU-X3aqboGeUMrsyOk9wdgQgVU7HzXsFQ8AS6tPYAKGFuyJApoGiaC1pve3YnEa3mVUROjoie_j-CcDRk0tb3JBsmX4d88hKJH9985WpT7AWGfmETfkTxAKXe4hdsqzHJ6lSvZA
>  => generated 3065 bytes in 792 msecs (HTTP/1.1 500) 2 headers in 100
> bytes (1 switches on core 0)
>
>
> What is the reason? Please suggest
>

Re: [flask] Unable to add user through Facebook login

From:
Jakub Muszynski
Date:
2013-05-27 @ 17:55
I did not deployed my app yet, but maybe that will help, let us know what
debug says...

facebook = oauth.remote_app('facebook',
    base_url='https://graph.facebook.com/',
    request_token_url=None,
    access_token_url='/oauth/access_token',
    authorize_url='https://www.facebook.com/dialog/oauth',
    consumer_key=FACEBOOK_APP_ID,
    consumer_secret=FACEBOOK_APP_SECRET,
    request_token_params={'scope': 'email'}
)


@app.route('/login/', methods=('GET', 'POST'))
def login_view():
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = form.get_user()
        login.login_user(user)
        return redirect(url_for('panel'))

    return facebook.authorize(callback=url_for('facebook_authorized',
        next=request.args.get('next') or request.referrer or None,
        _external=True))


@app.route('/login/authorized')
@facebook.authorized_handler
def facebook_authorized(resp):
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    session['oauth_token'] = (resp['access_token'], '')
    me = facebook.get('/me')
    #user = User()
    #user.login = me.data['id']
    #user.first_name = me.data['name']

    #user_exist =
db.session.query(User).filter_by(login=me.data['id']).first()
    #if user_exist:
    #    login.login_user(user_exist)
    #else:
    #    db.session.add(user)
    #    db.session.commit()
    #    login.login_user(user)

#    return 'Logged in as id=%s name=%s redirect=%s, oauthToken %s' % \
#        (me.data['id'], me.data['name'], request.args.get('next'),
get_facebook_oauth_token())
    return redirect(url_for('indexnew'))


It may be variable parsing in your url too...


On Sat, May 25, 2013 at 8:59 PM, Adam Patterson <adam@adamrt.com> wrote:

> Do you have app.debug = True ?
>
> You would get more information about the 500 error.
>
>
> On Sat, May 25, 2013 at 4:31 AM, Kundan Singh <ksingh.pilani@gmail.com>wrote:
>
>> Hello,
>> In my app i'm having a fblogin method for letting user login through
>> facebook.
>>
>> The complete logic is:
>>
>>
>> @app.route('/fblogin')
>> def fblogin():
>>     return facebook.authorize(callback=url_for('facebook_authorized',
>>         next=request.args.get('next') or request.referrer or None,
>>         _external=True))
>>
>> @app.route('/login/authorized')
>> @facebook.authorized_handler
>> def facebook_authorized(resp):
>>     next_url = request.args.get('next') or url_for('index')
>>     if resp is None:
>>         flash('You denied the login')
>>         return redirect(next_url)
>>
>>     session['fb_access_token'] = (resp['access_token'], '')
>>
>>     me = facebook.get('/me')
>>     user = Users.query.filter_by(fb_id=me.data['id']).first()
>>
>>     if user is None:
>>       fb_id = me.data['id']
>>
>>       if me.data['username']:
>>         fb_username = me.data['username']
>>       else:
>>         fb_username = me.data['name']
>>
>>       fb_email = me.data['email']
>>
>>       role = 5
>>       user = Users(fb_username, 'temp',fb_email, role)
>>       user.fb_id = me.data['id']
>>       user.activate  = True
>>       user.created = datetime.utcnow()
>>       db.session.add(user)
>>       db.session.commit()
>>     session['user_id'] = user.uid
>>
>>     flash('You are now logged in as %s' % user.username)
>>     return redirect(url_for('index'))
>>
>>
>> @facebook.tokengetter
>> def get_facebook_oauth_token():
>>     return session.get('fb_access_token')
>>
>>
>> When i use this method in localhost:5000 it works fine.
>>
>> Now i deployed this code on mywebsite.com and when i try to login using
>> facebook, it asks for permission and when click *Okay* it comes back and
>> A error 500 page is served with url in browser being:
>>
>>
>> 
http://www.mywebsite.com/login/authorized?next=http%3A%2F%2Fwww.backmunch.com%2F&code=AQDed70eh7mGRuNleJqDSzdfasfdsafeewfasdfadfdsafadfasdfaf3xZCVAXvnHRnw-Q4G2s3Wf2q57kYHXWfddfadscadf2dfs2sdfvvdJeWgLVUiQozqJ8ExLSmbawUal__WJ_gMmaWxAejcgrCiB0neHvGyt4kHh-8-UQ55tg-9nmiIYg-dF89zkW3ROHUmJI476TM7H4lJJXAaM9fANN3u2eWeoEFIwWqRxpt3EEd8QlWGzbFaLPrAwsaqwNNSUSX7f9TUxFSnMk9RigeF6I#_=_<http://www.backmunch.com/login/authorized?next=http%3A%2F%2Fwww.backmunch.com%2F&code=AQDed70eh7mGRuNleJqDSzmbduKFFC7NyzAuO5b0QGRCrC2xiNlV-JeCPgQx2-Jdj5jr0nlOlw9Ksmcya4bJIs-sNrXYi3f3xZCVAXvnHRnw-Q4G2s3Wf2q57kYHXWNkrO6hWTmZWP3BvV4mUTvvdJeWgLVUiQozqJ8ExLSmbawUal__WJ_gMmaWxAejcgrCiB0neHvGyt4kHh-8-UQ55tg-9nmiIYg-dF89zkW3ROHUmJI476TM7H4lJJXAaM9fANN3u2eWeoEFIwWqRxpt3EEd8QlWGzbFaLPrAwsaqwNNSUSX7f9TUxFSnMk9RigeF6I#_=_>
>>
>> On locahost it was successfully coming to 
http://www.mywebsite.com/#_=_but not in deployed case.
>>
>> Since mysite's log says:
>>
>> [Sat May 25 11:25:32 2013] GET /fblogin => generated 605 bytes in 3 msecs
>> (HTTP/1.1 302) 4 headers in 566 bytes (1 switches on core 0)
>> [pid: 11797|app: 0|req: 73/73] 116.202.84.0 () {40 vars in 1652 bytes}
>>
>> [Sat May 25 11:25:36 2013] GET /login/authorized?next=http%3A%2F%
>> 2Fwww.backmunch.com
>> 
%2F&code=AQB1-7Fdd7xRwqWv5uEQLiHxbUikaOKRoDS1FNBNTnbNSiK5s4dcFhQw-m_H7eFG6Rh25GiIzP6gwxrXLZV0zeSLDLg0MplDUjDMZR4PGpQc-Wr3Dq5lvivEv7a_vHy3abLTnkD7zGjCAGsBXApFsT-Lr81m9BBVkjiP5kX76Nv7SNugy9ynvl3bdWHleU-X3aqboGeUMrsyOk9wdgQgVU7HzXsFQ8AS6tPYAKGFuyJApoGiaC1pve3YnEa3mVUROjoie_j-CcDRk0tb3JBsmX4d88hKJH9985WpT7AWGfmETfkTxAKXe4hdsqzHJ6lSvZA
>>  => generated 3065 bytes in 792 msecs (HTTP/1.1 500) 2 headers in 100
>> bytes (1 switches on core 0)
>>
>>
>> What is the reason? Please suggest
>>
>
>