2020if major_py_version == 2 and minor_py_version > 4 :
2121 import oauth2 as oauth
2222else :
23- import oauth2_version as oauth
23+ import oauth2_version as oauth
2424
2525import urllib
2626import urllib2
3333
3434import urlparse
3535
36- __version__ = '0.3.1 '
36+ __version__ = '0.3.2 '
3737
3838REQUEST_TOKEN_URL = 'https://sso.openx.com/api/index/initiate'
3939ACCESS_TOKEN_URL = 'https://sso.openx.com/api/index/token'
4343
4444class Client (object ):
4545
46- def __init__ (self , domain , realm , consumer_key , consumer_secret ,
46+ def __init__ (self , domain , consumer_key , consumer_secret ,
47+ realm = '' ,
4748 callback_url = 'oob' ,
4849 scheme = 'http' ,
4950 request_token_url = REQUEST_TOKEN_URL ,
@@ -57,9 +58,9 @@ def __init__(self, domain, realm, consumer_key, consumer_secret,
5758 """
5859
5960 domain -- Your UI domain. The API is accessed off this domain.
60- realm -- This is no longer used. Just specify None.
6161 consumer_key -- Your consumer key.
6262 consumer_secret -- Your consumer secret.
63+ realm -- Optional realm.
6364 callback_url -- Callback URL to redirect to on successful authorization.
6465 We default to 'oob' for headless login.
6566 request_token -- Only override for debugging.
@@ -68,12 +69,13 @@ def __init__(self, domain, realm, consumer_key, consumer_secret,
6869 api_path -- Only override for debugging.
6970 http_proxy -- Optional proxy to send HTTP requests through.
7071 """
71-
72+
7273 self .domain = domain
7374 self .consumer_key = consumer_key
7475 self .consumer_secret = consumer_secret
76+ self .realm = realm
7577 self .callback_url = callback_url
76- self .scheme = scheme
78+ self .scheme = scheme
7779 self .request_token_url = request_token_url
7880 self .access_token_url = access_token_url
7981 self .authorization_url = authorization_url
@@ -130,8 +132,9 @@ def _sign_request(self, req):
130132 oauth .SignatureMethod_HMAC_SHA1 (),
131133 self ._consumer ,
132134 self ._token )
133-
134- req .headers .update (oauth_req .to_header ())
135+
136+ req .headers .update (oauth_req .to_header (realm = self .realm ))
137+
135138 return \
136139 urllib2 .Request (req .get_full_url (), headers = req .headers , data = data )
137140
@@ -159,7 +162,7 @@ def request(self, url, method='GET', headers={}, data=None, sign=False):
159162 # Everything needs to be UTF-8 for urlencode:
160163 data_utf8 = req .get_data ()
161164 for i in data_utf8 :
162- data_utf8 [i ] = data_utf8 [i ].encode ('utf-8' )
165+ data_utf8 [i ] = data_utf8 [i ].encode ('utf-8' )
163166 req .add_data (urllib .urlencode (data_utf8 ))
164167
165168 # In 2.4 and 2.5, urllib2 throws errors for all non 200 status codes.
@@ -392,6 +395,7 @@ def client_from_file(file_path='.ox3rc', env=None):
392395
393396 # Load optional parameters.
394397 optional_params = [
398+ 'realm' ,
395399 'callback_url' ,
396400 'scheme' ,
397401 'request_token_url' ,
0 commit comments