Permalink
Browse files

Updated Foursquare callback view.

  • Loading branch information...
mihanovak committed Jun 4, 2012
1 parent 2cfec77 commit 3e27463950a05a30faccee63d1226b58006e61cf
Showing with 15 additions and 1 deletion.
  1. +15 −1 piplmesh/account/views.py
View
@@ -187,9 +187,23 @@ class FoursquareCallbackView(generic_views.RedirectView):
def get(self, request, *args, **kwargs):
if 'code' in request.GET:
- user = auth.authenticate(foursquare_token=request.GET['code'], request=request)
+ args = {
+ 'client_id': settings.FOURSQUARE_CLIENT_ID,
+ 'client_secret': settings.FOURSQUARE_CLIENT_SECRET,
+ 'redirect_uri': request.build_absolute_uri(urlresolvers.reverse('foursquare_callback')),
+ 'code': request.GET['code'],
+ 'grant_type': 'authorization_code',
+ }
+
+ response = json.load(urllib.urlopen('https://foursquare.com/oauth2/access_token', urllib.urlencode(args)))
+ # TODO: Handle error, what if response does not contain access token?
+ access_token = response['access_token']
+
+ user = auth.authenticate(foursquare_access_token=access_token, request=request)
assert user.is_authenticated()
+
auth.login(request, user)
+
return super(FoursquareCallbackView, self).get(request, *args, **kwargs)
else:
# TODO: Message user that they have not been logged in because they cancelled the foursquare app

0 comments on commit 3e27463

Please sign in to comment.