Skip to content

Commit

Permalink
Merge pull request #11 from CircleUp/master
Browse files Browse the repository at this point in the history
Support for exchange of short-lived access token for long-lived access token
  • Loading branch information
jmg committed Dec 12, 2012
2 parents 550383b + a54405f commit d35d504
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pyfb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ def get_access_token(self, app_secret_key, secret_code, redirect_uri):
self.expires = data.get('expires')
return self.access_token

def exchange_token(self, app_secret_key, exchange_token):

self.secret_key = app_secret_key

url_path = self._get_url_path({
"grant_type": 'fb_exchange_token',
"client_id": self.app_id,
"client_secret" : app_secret_key,
"fb_exchange_token" : exchange_token,
})
url = "%s%s" % (self.BASE_TOKEN_URL, url_path)

data = self._make_request(url)

if not "access_token" in data:
ex = self.factory.make_object('Error', data)
raise PyfbException(ex.error.message)

data = dict(parse_qsl(data))
self.access_token = data.get('access_token')
self.expires = data.get('expires')
return self.access_token, self.expires

def get_dialog_url(self, redirect_uri):

if redirect_uri is None:
Expand Down
7 changes: 7 additions & 0 deletions pyfb/pyfb.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ def get_access_token(self, app_secret_key, secret_code, redirect_uri=None):
"""
return self._client.get_access_token(app_secret_key, secret_code, redirect_uri)

def exchange_token(self, app_secret_key, exchange_token):
"""
Exchanges a short-lived access token (like those obtained from client-side JS api)
for a longer-lived access token
"""
return self._client.exchange_token(app_secret_key, exchange_token)

def show_dialog(self, redirect_uri=None):
"""
Open your prefered web browser to make the authentication request
Expand Down

0 comments on commit d35d504

Please sign in to comment.