Skip to content

Commit

Permalink
add an option for customizing the successful authentication page
Browse files Browse the repository at this point in the history
  • Loading branch information
pcardune committed Jan 15, 2012
1 parent fca110e commit 799fa86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ running code downloaded from the internet like this.

For many api calls, you will need to authenticate your script with Facebook.
fbconsole makes this easy by providing an `authenticate` function. If your
script needs extended permissions, for example to post a status update, you can
specify which extended permissions to request with the AUTH_SCOPE setting. For
example:
script needs
[extended permissions](https://developers.facebook.com/docs/reference/api/permissions/),
for example to post a status update, you can specify which extended permissions
to request with the AUTH_SCOPE setting. For example:

import fbconsole

Expand Down Expand Up @@ -115,6 +116,9 @@ There are two other options you can specify.
- `ACCESS_TOKEN_FILE` controls where the access token gets stored on the file
system. The default is `.fb_access_token`.

- `AUTH_SUCCESS_HTML` is the html page content displayed to the user in their browser
window once they have successfully authenticated.


## Feedback ##

Expand Down
11 changes: 7 additions & 4 deletions src/fbconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
ACCESS_TOKEN_FILE = '.fb_access_token'
AUTH_SCOPE = []

AUTH_SUCCESS_HTML = """
You have successfully logged in to facebook with fbconsole.
You can close this window now.
"""

__all__ = [
'help',
'authenticate',
Expand Down Expand Up @@ -151,8 +156,7 @@ def do_GET(self):
else:
data['expires_at'] = int(time.time()+int(expiration))
open(ACCESS_TOKEN_FILE,'w').write(json.dumps(data))
self.wfile.write("You have successfully logged in to facebook with fbconsole. "
"You can close this window now.")
self.wfile.write(AUTH_SUCCESS_HTML)
else:
self.wfile.write('<html><head>'
'<script>location = "?"+location.hash.slice(1);</script>'
Expand All @@ -178,7 +182,7 @@ def authenticate():
"""Authenticate with facebook so you can make api calls that require auth.
Alternatively you can just set the ACCESS_TOKEN global variable in this
module to an access token you get from facebook.
module to set an access token you get from facebook.
If you want to request certain permissions, set the AUTH_SCOPE global
variable to the list of permissions you want.
Expand All @@ -194,7 +198,6 @@ def authenticate():
needs_auth = False

if needs_auth:
print "Logging you in to facebook..."
webbrowser.open('https://www.facebook.com/dialog/oauth?' +
urlencode({'client_id':APP_ID,
'redirect_uri':'http://127.0.0.1:%s/' % SERVER_PORT,
Expand Down

0 comments on commit 799fa86

Please sign in to comment.