Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of heroku.com:mugged

  • Loading branch information...
commit 3de226d21b34f81d45843d83dcd9bcca7a79cdd8 2 parents 4962e80 + ab71558
@bradmann authored
Showing with 12 additions and 5 deletions.
  1. +1 −1  mugged/settings.py
  2. +11 −4 muggedapp/middleware/fbauth.py
View
2  mugged/settings.py
@@ -155,7 +155,7 @@
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
- },
+ }
}
}
View
15 muggedapp/middleware/fbauth.py
@@ -5,7 +5,9 @@
import hashlib
import json
import urllib
+import urlparse
import requests
+import datetime
oauth_uri = 'https://www.facebook.com/dialog/oauth?client_id=' + settings.FBAPI_APP_ID + '&scope=' + ','.join(settings.FBAPI_SCOPE)
at_uri = 'https://graph.facebook.com/oauth/access_token?client_id=' + settings.FBAPI_APP_ID + '&client_secret=' + settings.FBAPI_APP_SECRET
@@ -41,12 +43,17 @@ def process_request(self, request):
elif request.method == 'GET':
code = request.GET.get('code')
access_token = request.session.get('access_token')
- if not access_token and not code:
+ expires = request.session.get('expires')
+ if (expires and datetime.datetime.now() > expires) or (not access_token and not code):
return HttpResponseRedirect(oauth_uri + '&redirect_uri=' + request.build_absolute_uri() + '&state=login')
elif code:
req = requests.get(at_uri + '&redirect_uri=' + request.build_absolute_uri() + '&code=' + code)
- d = urllib.parse.parse_qs(req.text)
- request.session['access_token'] = d['access_token']
- return None
+ if req.status_code == 200:
+ d = urlparse.parse_qs(req.text)
+ request.session['access_token'] = d['access_token'][0]
+ request.session['expires'] = datetime.datetime.now() + datetime.timedelta(seconds=int(d['expires'][0]) - 20)
+ return None
+ else:
+ return HttpResponse('Error retreiving Facebook access_token.')
else:
return None
Please sign in to comment.
Something went wrong with that request. Please try again.