public
Description: An HTTP proxy for signing OAuth requests
Clone URL: git://github.com/mojodna/oauth-proxy.git
Search Repo:
refactored to allow it to run from twistd directly
mojodna (author)
Tue Apr 22 18:09:44 -0700 2008
commit  e111113a37bd86cbf0a662d93ebb514f0c5ac087
tree    d9f8c9cc8444febb70915b7d86996aab98a7f4d5
parent  23e726e9a38be26eb09f2f8f3c8ba09c4d82eda2
...
1
2
3
 
 
...
1
2
 
3
4
0
@@ -1,4 +1,5 @@
0
 *.tap
0
 *.pyc
0
-twistd.pid
0
+dropin.cache
0
+twistd.*
0
...
8
9
10
 
 
 
...
8
9
10
11
12
13
0
@@ -8,4 +8,7 @@
0
 twistd -nf oauth_proxy.tap
0
 
0
 (For mktap to find oauth_proxy, you may need to make sure that "." is in your PYTHONPATH)
0
+
0
+Or, just run it with twistd:
0
+twistd -n oauth_proxy --consumer_key <consumer key> --consumer_secret <consumer secret> [--token <token>] [--token_secret <token secret>] [-p <proxy port>] [--ssl]
0
...
 
...
1
0
@@ -1 +1,2 @@
0
+- create oauth_proxy.tac (similar to oauth_proxy/tap.py) for use with twistd, without requiring mktap (see http://twistedmatrix.com/projects/core/documentation/howto/application.html)
...
7
8
9
 
 
10
 
11
12
13
14
 
15
16
17
18
19
20
...
22
23
24
 
25
26
27
...
31
32
33
 
34
35
36
...
44
45
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
48
49
...
7
8
9
10
11
12
13
14
15
 
 
16
17
 
 
18
19
20
...
22
23
24
25
26
27
28
...
32
33
34
35
36
37
38
...
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
0
@@ -7,14 +7,14 @@
0
 ## TODO
0
 # - provide a way of specifying access tokens (and possibly secrets, if not handled via lookup) - Basic Auth?
0
 
0
+import cgi
0
+from oauth import oauth
0
 import sgmllib, re, urlparse
0
+import sys
0
 from twisted.internet import ssl
0
 from twisted.web import proxy, http
0
-import sys
0
-from twisted.python import log
0
+from twisted.python import log, usage
0
 from zope.interface import implements, Interface
0
-from oauth import oauth
0
-import cgi
0
 
0
 class IOAuthCredentialProvider(Interface):
0
   """An OAuth credential provider"""
0
@@ -22,6 +22,7 @@
0
   def fetchCredentials():
0
     """Fetch credentials"""
0
 
0
+
0
 class StaticOAuthCredentialProvider:
0
   implements(IOAuthCredentialProvider)
0
   
0
@@ -31,6 +32,7 @@
0
   def fetchCredentials(self):
0
     return self.credentials
0
 
0
+
0
 class OAuthCredentials:
0
   """
0
   A container for OAuth credentials
0
@@ -44,6 +46,20 @@
0
       self.oauthToken = None
0
       
0
     self.signatureMethod = signatureMethod
0
+
0
+
0
+class Options(usage.Options):
0
+ synopsis = "Usage: mktap oauth_proxy --consumer_key <consumer key> --consumer_secret <consumer secret> [--token <token>] [--token_secret <token secret>] [-p <proxy port>] [--ssl] "
0
+ longdesc = "Makes an OAuth HTTP proxy server.."
0
+ optParameters = [
0
+ ['consumer_key', None, None, "OAuth Consumer Key"],
0
+ ['consumer_secret', None, None, "OAuth Consumer Secret"],
0
+ ['token', None, None, "OAuth Access/Request Token"],
0
+ ['token_secret', None, None, "OAuth Access/Request Token Secret"],
0
+ ['port', 'p', 8001, "Proxy port", int],
0
+ ]
0
+
0
+ optFlags = [['ssl', 's']]
0
 
0
 
0
 class OAuthProxyClient(proxy.ProxyClient):
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,40 +1 @@
0
-import sys
0
-from twisted.application import internet, service
0
-from twisted.python import usage
0
-import oauth_proxy
0
-
0
-class Options(usage.Options):
0
- synopsis = "Usage: mktap oauth_proxy --consumer_key <consumer key> --consumer_secret <consumer secret> [--token <token>] [--token_secret <token secret>] [-p <proxy port>] [--ssl] "
0
- longdesc = "Makes an OAuth HTTP proxy server.."
0
- optParameters = [
0
- ['consumer_key', None, None, "OAuth Consumer Key"],
0
- ['consumer_secret', None, None, "OAuth Consumer Secret"],
0
- ['token', None, None, "OAuth Access/Request Token"],
0
- ['token_secret', None, None, "OAuth Access/Request Token Secret"],
0
- ['port', 'p', 8001, "Proxy port", int],
0
- ]
0
-
0
- optFlags = [['ssl', 's']]
0
-
0
-def makeService(config):
0
- app = service.Application("oauth_proxy")
0
-
0
- useSSL = config["ssl"]
0
-
0
- consumerKey = config["consumer_key"]
0
- consumerSecret = config["consumer_secret"]
0
- if config.has_key("token") and config.has_key("token_secret"):
0
- token = config["token"]
0
- tokenSecret = config["token_secret"]
0
- else:
0
- token = tokenSecret = None
0
-
0
- port = config["port"]
0
-
0
- credentials = oauth_proxy.OAuthCredentials(consumerKey, consumerSecret, token, tokenSecret)
0
-
0
- proxy = internet.TCPServer(port, oauth_proxy.OAuthProxyFactory(credentials, useSSL))
0
- proxy.setServiceParent(app)
0
-
0
- return app
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
 
16
17
18
19
20
...
1
2
 
3
4
 
 
 
 
 
 
 
 
 
 
5
6
7
 
8
9
10
0
@@ -1,20 +1,10 @@
0
 import sys
0
 from twisted.application import internet, service
0
-from twisted.python import usage
0
 import oauth_proxy
0
 
0
-class Options(usage.Options):
0
- synopsis = "Usage: mktap oauth_proxy --consumer_key <consumer key> --consumer_secret <consumer secret> [--token <token>] [--token_secret <token secret>] [-p <proxy port>] [--ssl] "
0
- longdesc = "Makes an OAuth HTTP proxy server.."
0
- optParameters = [
0
- ['consumer_key', None, None, "OAuth Consumer Key"],
0
- ['consumer_secret', None, None, "OAuth Consumer Secret"],
0
- ['token', None, None, "OAuth Access/Request Token"],
0
- ['token_secret', None, None, "OAuth Access/Request Token Secret"],
0
- ['port', 'p', 8001, "Proxy port", int],
0
- ]
0
+class Options(oauth_proxy.Options):
0
+ pass
0
 
0
- optFlags = [['ssl', 's']]
0
 
0
 def makeService(config):
0
   s = service.MultiService()
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
0
@@ -1 +1,36 @@
0
+from zope.interface import implements
0
+
0
+from twisted.python import usage
0
+from twisted.plugin import IPlugin
0
+from twisted.application.service import IServiceMaker
0
+from twisted.application import internet
0
+
0
+from oauth_proxy import oauth_proxy
0
+
0
+class OAuthProxyServiceMaker(object):
0
+ implements(IServiceMaker, IPlugin)
0
+ tapname = "oauth_proxy"
0
+ description = "OAuth HTTP proxy"
0
+ options = oauth_proxy.Options
0
+
0
+ def makeService(self, options):
0
+ useSSL = options["ssl"]
0
+
0
+ consumerKey = options["consumer_key"]
0
+ consumerSecret = options["consumer_secret"]
0
+ if options.has_key("token") and options.has_key("token_secret"):
0
+ token = options["token"]
0
+ tokenSecret = options["token_secret"]
0
+ else:
0
+ token = tokenSecret = None
0
+
0
+ port = options["port"]
0
+
0
+ credentials = oauth_proxy.OAuthCredentials(consumerKey, consumerSecret, token, tokenSecret)
0
+ credentialProvider = oauth_proxy.StaticOAuthCredentialProvider(credentials)
0
+
0
+ return internet.TCPServer(port, oauth_proxy.OAuthProxyFactory(credentialProvider, useSSL))
0
+
0
+
0
+serviceMaker = OAuthProxyServiceMaker()

Comments

    No one has commented yet.