Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suppose you are using the JS Facebook library if you say that the oauth just pop ups. I would go the simpler oauth redirect way, using a the following :</p> <pre><code>def build_authentication_redirect(self): args = {} args["client_id"]=self.app_id args["redirect_uri"]=self.redirect_uri args["scope"]=",".join(self.req_perms) redirect_url = "https://www.facebook.com/dialog/oauth?"+urllib.urlencode(args) redirect_code = """ &lt;script type="text/javascript"&gt; top.location.href='%s'; &lt;/script&gt; """ % redirect_url; return HttpResponse(redirect_code,mimetype="text/html") </code></pre> <p>Where self.app_id is your facebook app id. Where self.redirect_uri is the url the user will be redirected after login. Where self.scope is built from self.req_perms which is an array of the required permissions.</p> <p>After that they user will be redirected to redirect_uri with the access token in post 'signed_request' parameter, you can use the following function to decode it :</p> <pre><code>def load_signed_request(self, signed_request): """Load the user state from a signed_request value""" sig, payload = signed_request.split(u'.', 1) sig = self.base64_url_decode(sig) data = json.loads(self.base64_url_decode(payload)) expected_sig = hmac.new(self.app_secret, msg=payload, digestmod=hashlib.sha256).digest() # allow the signed_request to function for upto 1 day if sig == expected_sig and data[u'issued_at'] &gt; (time.time() - 86400): return data.get(u'user_id'), data.get(u'oauth_token') else: return None,None </code></pre> <p>Example : </p> <pre><code>sigreq =request.POST.get('signed_request', None) user_id,access_token = load_signed_request(sigreq) </code></pre> <p>Again you will need self.app_secret and the following function :</p> <pre><code>@staticmethod def base64_url_decode(data): data = data.encode(u'ascii') data += '=' * (4 - (len(data) % 4)) return base64.urlsafe_b64decode(data) </code></pre> <p>I had a lot of trouble with FB JS login and auth, especially on different browsers, this way is the more robust way I could find :)</p> <p>Btw If you want my facebook.py file I can put it available online somewhere ... It even has a @fbsig_required and @fbsig_redirect view decorators ...</p> <p>Oh Also here are my imports :</p> <pre><code>import cgi import hashlib import time import urllib import base64 import datetime import hmac from django.conf import settings from django.http import HttpResponseRedirect,HttpResponse,HttpResponseNotFound </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload