2
1

Hello, I have a problem with facebook login.. some novice users complain that they couldn't use facebook login which appears to be caused by the pop-up blocker..

is there a solution to this problem? specially that stackoverflow do not have such problem!

asked 27 Sep '11, 00:01

Fahd's gravatar image

Fahd
171249
accept rate: 20%

edited 27 Sep '11, 08:30

@Fahd, all meta.osqa.net postings are required to have a clear, specific question in their title field. Please correct the title of this posting right away. Thanks.

(27 Sep '11, 07:12) rickross ♦♦

hope its clearer now :)

(27 Sep '11, 08:30) Fahd

I have figured it out :D

the changes apply to 3 files:

1- forum_modules/facebookauth/templates/button.html: replace the whole file with this link:

<a style="position: relative; top: -8px;" href="http://www.facebook.com/dialog/oauth/?scope=email&client_id={{ provider.API_KEY }}&redirect_uri=http://www.YOURDOMAIN.COM{% url auth_provider_done provider=provider.id %}"><img src="{% media '/media/images/openid/facebook.gif' %}" /></a>

2- forum_modules/facebookauth/authentication.py: replace the following 2 functions with the new content: def process_authentication_request(self, request): API_KEY = str(settings.FB_API_KEY)

    if 'code' in request.GET:
        code = '%s' % request.GET['code']
        fb_response = urlopen('https://graph.facebook.com/oauth/access_token?scope=email&client_id=%s&redirect_uri=http://www.YOURDOMAIN.COM/account/facebook/done/&client_secret=%s&code=%s' % (API_KEY, str(settings.FB_APP_SECRET) , code))
        fb_string = fb_response.read()
        parsed_fbs = parse_qs(smart_unicode(fb_string))
        json = load_json(urlopen('https://graph.facebook.com/me?access_token=%s' % parsed_fbs['access_token'][0]))

first_name = smart_unicode(json['first_name'])
        last_name = smart_unicode(json['last_name'])
        full_name = '%s %s' % (first_name, last_name)

# There is a limit in the Django user model for the username length (no more than 30 characaters)
        if len(full_name) <= 30:
            username = full_name
        # If the full name is too long use only the first
        elif len(first_name) <= 30:
            username = first_name
        # If it's also that long -- only the last
        elif len(last_name) <= 30:
            username = last_name
        # If the real name of the user is indeed that weird, let him choose something on his own =)
        else:
            username = ''

# Check whether the length if the email is greater than 75, if it is -- just replace the email
        # with a blank string variable, otherwise we're going to have trouble with the Django model.
        email = smart_unicode(json['email'])
        if len(email) > 75:
            email = ''

request.session['fb_username'] = username
        request.session['fb_email'] = email
        return smart_unicode(json['id'])
    else:
        raise InvalidAuthentication(_('The authentication with Facebook connect failed, cannot find authentication tokens'))
def check_session_expiry(self, cookies):
    return datetime.fromtimestamp(float(self.parsed_fbs['expires'][0])) > datetime.now()

def get_user_data(self, request):
    username = request.session.get('fb_username','')
    email = request.session.get('fb_email','')
    try:
        del request.session['fb_username']
        del request.session['fb_email']
    except KeyError:
        pass
    # Return the user data.
    return {
        'username': username,
        'email': email,
    }

3- forum/views/auth.py line 198: change the cookies object to request object

if provider_class.__class__.__name__ == 'FacebookAuthConsumer':
        user_data = provider_class.get_user_data(request)

and do not forget to change the links in the code to your domain and build each file and then restart apache to the changes to take effect :D

link

answered 30 Sep '11, 17:19

Fahd's gravatar image

Fahd
171249
accept rate: 20%

edited 30 Sep '11, 17:21

Great work Fahd. There were a couple of minor details missing which I outlined in my answer below.

(15 Mar, 00:16) Yaz Sinan

Thanks Fahd, just a couple of points to complement your post.

1) Make sure you add the following inclusions to forum_modules/facebookauth/authentication.py

from django.utils.encoding import smart_unicode 
from urlparse import parse_qs

2) Make sure you add the following inclusion to forum_modules/facebookauth/templates/button.html

{% load extra_tags %}

3) For forum/views/auth.py, I just changed

provider_class = AUTH_PROVIDERS[auth_provider].consumer
user_data = provider_class.get_user_data(request.session['assoc_key'])

to

provider_class = AUTH_PROVIDERS[auth_provider].consumer

if provider_class.__class__.__name__ == 'FacebookAuthConsumer':
    user_data = provider_class.get_user_data(request)
else:            
    user_data = provider_class.get_user_data(request.session['assoc_key'])

I'm not entirely sure what Fahd recommended on this last code change, but this is what worked for me.

link

answered 15 Mar, 00:15

Yaz%20Sinan's gravatar image

Yaz Sinan
513
accept rate: 50%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×75
×40
×12
×3

Asked: 27 Sep '11, 00:01

Seen: 1,757 times

Last updated: 15 Mar, 00:16

powered by OSQA