Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Dropbox OAuth

  • Loading branch information...
commit 5cfa56c2e77d84b9825450c0de145839e99d60fb 1 parent 79ff7be
@SilentGob SilentGob authored Mike Knapp committed
Showing with 44 additions and 0 deletions.
  1. +44 −0 oauth.py
View
44 oauth.py
@@ -76,6 +76,8 @@ def get_oauth_client(service, key, secret, callback_url):
return YahooClient(key, secret, callback_url)
elif service == "myspace":
return MySpaceClient(key, secret, callback_url)
+ elif service == "dropbox":
+ return DropboxClient(key, secret, callback_url)
else:
raise Exception, "Unknown OAuth service %s" % service
@@ -464,3 +466,45 @@ def _lookup_user_info(self, access_token, access_secret):
user_info["picture"] = data["image"]["imageUrl"]
return user_info
+
+class DropboxClient(OAuthClient):
+ """Dropbox Client.
+
+ A client for talking to the Dropbox API using OAuth as the
+ authentication model.
+ """
+
+ def __init__(self, consumer_key, consumer_secret, callback_url):
+ """Constructor."""
+
+ OAuthClient.__init__(self,
+ "dropbox",
+ consumer_key,
+ consumer_secret,
+ "https://api.dropbox.com/0/oauth/request_token",
+ "https://api.dropbox.com/0/oauth/access_token",
+ callback_url)
+
+ def get_authorization_url(self):
+ """Get Authorization URL."""
+
+ token = self._get_auth_token()
+ return "http://www.dropbox.com/0/oauth/authorize?oauth_token=%s&oauth_callback=%s" %( token, urlquote(self.callback_url))
+
+ def _lookup_user_info(self, access_token, access_secret):
+ """Lookup User Info.
+
+ Lookup the user on Dropbox.
+ """
+
+ response = self.make_request(
+ "http://api.dropbox.com/0/account/info",
+ token=access_token, secret=access_secret, protected=True)
+
+ data = json.loads(response.content)
+ user_info = self._get_default_user_info()
+ user_info["id"] = data["uid"]
+ user_info["name"] = data["display_name"]
+ user_info["country"] = data["country"]
+
+ return user_info
Please sign in to comment.
Something went wrong with that request. Please try again.