Permalink
Browse files

Fixed server port config

  • Loading branch information...
1 parent a8fc22f commit 44b9d0446dc0eb01ea6b82b3afa1876c3f7d3d3a Georges Gouriten committed Jun 28, 2012
View
34 auth.py
@@ -7,7 +7,8 @@
import oauth2 as oauth
-AUTH_PATH = 'apiblender/config/apis/auth/'
+AUTH_PATH = os.path.dirname(__file__) + '/config/apis/auth/'
+
class AuthManager:
@@ -72,9 +73,13 @@ def __init__(self, auth_config):
# TODO: validation
self.url = auth_config["url"]
self.url_parameters = auth_config["url_parameters"]
+ if "port" in auth_config.keys():
+ self.port = auth_config["port"]
+ else:
+ self.port = 443
- def request_parameters(self, host, port):
- c = httplib.HTTPSConnection(host, 443, timeout = 10)
+ def request_parameters(self, host):
+ c = httplib.HTTPSConnection(host, self.port, timeout = 10)
total_path = "%s?%s" % (self.url,urllib.urlencode(self.url_parameters))
c.request('GET', total_path)
r = c.getresponse()
@@ -92,7 +97,7 @@ def request_parameters(self, host, port):
def make_request(self, server, interaction, url_parameters):
c = httplib.HTTPSConnection( server.host,
- 443,
+ self.port,
timeout = 10 )
url_parameters.update(self.auth_url_parameters)
total_path = "%s?%s" % ( interaction.request.url_root_path,
@@ -115,8 +120,12 @@ def __init__(self, auth_config):
self.request_token_url = auth_config["request_token_url"]
self.access_token_url = auth_config["access_token_url"]
self.authorize_url = auth_config["authorize_url"]
+ if "port" in auth_config.keys():
+ self.port = auth_config["port"]
+ else:
+ self.port = 443
- def request_parameters(self, host, port):
+ def request_parameters(self, host):
consumer = oauth.Consumer(self.consumer_key, self.consumer_secret)
client = oauth.Client(consumer)
# Getting the request token
@@ -175,21 +184,30 @@ class AuthAPIKey(Authentication):
def __init__(self, auth_config):
# TODO: validation
self.auth_url_parameters = auth_config["url_parameters"]
- self.https = auth_config["https"]
+ if 'https' in auth_config.keys():
+ self.https = auth_config["https"]
+ else:
+ self.https = false
+ if "port" in auth_config.keys():
+ self.port = auth_config["port"]
+ else:
+ self.port = 443
def request_parameters(self, host, port):
pass
def make_request(self, server, interaction, url_parameters):
if self.https:
c = httplib.HTTPSConnection( server.host,
- 443,
+ self.port,
timeout = 10 )
else:
c = httplib.HTTPConnection( server.host,
- server.port,
+ self.port,
timeout = 10 )
url_parameters.update(self.auth_url_parameters)
+ print url_parameters
+ print self.auth_url_parameters
total_path = "%s?%s" % ( interaction.request.url_root_path,
urllib.urlencode(url_parameters) )
print "Request: %s%s" % (server.host, total_path)
@@ -2,5 +2,7 @@
"type": "api_key",
"url_parameters": {
"api_key": "YOURAPIKEY"
- }
+ },
+ "https": false,
+ "port": 80
}
@@ -2,5 +2,7 @@
"type": "api_key",
"url_parameters": {
"key": "YOURAPIKEY"
- }
+ },
+ "https": true,
+ "port": 443
}
@@ -5,5 +5,7 @@
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"grant_type": "client_credentials"
- }
+ },
+ "https": false,
+ "port": 80
}
@@ -4,5 +4,7 @@
"consumer_secret": "",
"request_token_url": "https://api.twitter.com/oauth/request_token",
"access_token_url": "http://api.twitter.com/oauth/access_token",
- "authorize_url": "http://api.twitter.com/oauth/authorize"
+ "authorize_url": "http://api.twitter.com/oauth/authorize",
+ "https": true,
+ "port": 443
}
@@ -2,5 +2,7 @@
"type": "api_key",
"url_parameters": {
"key": "YOURAPIKEY"
- }
+ },
+ "https": true,
+ "port": 443
}
View
@@ -1,5 +1,8 @@
#!/usr/bin/python
-# A very simple example of API Blender
+# Simple examples of the options offered by API Blender
+#
+# /!\ Example.py must be moved to a parent directory of apiblender
+#
import main
blender = main.Blender()

0 comments on commit 44b9d04

Please sign in to comment.