Skip to content

Commit 9a979ee

Browse files
jmoldowLu Pan
authored andcommitted
Correct OAuth2 url config
The configuration was using an out-of-date url for OAuth2, possibly from an deprecated version of the Box API. Use the correct (according to the official documentation at <https://developers.box.com/docs/>) urls for OAuth2.
1 parent 2915248 commit 9a979ee

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

boxsdk/auth/oauth2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def get_authorization_url(self, redirect_url):
9999
(`unicode`, `unicode`)
100100
"""
101101
csrf_token = self._get_state_csrf_token()
102-
return '{0}/authorize?state={1}&response_type=code&client_id={2}&redirect_uri={3}'.format(
103-
API.OAUTH2_URL,
102+
return '{0}?state={1}&response_type=code&client_id={2}&redirect_uri={3}'.format(
103+
API.OAUTH2_AUTHORIZE_URL,
104104
csrf_token,
105105
self._client_id,
106106
redirect_url,
@@ -201,7 +201,7 @@ def send_token_request(self, data, access_token):
201201
:rtype:
202202
(`unicode`, `unicode`)
203203
"""
204-
url = '{base_auth_url}/token'.format(base_auth_url=API.OAUTH2_URL)
204+
url = '{base_auth_url}/token'.format(base_auth_url=API.OAUTH2_API_URL)
205205
headers = {'content-type': 'application/x-www-form-urlencoded'}
206206
network_response = self._network_layer.request(
207207
'POST',

boxsdk/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ class API(object):
77
"""Configuration object containing the URLs for the Box API."""
88
BASE_API_URL = 'https://api.box.com/2.0'
99
UPLOAD_URL = 'https://upload.box.com/api/2.0'
10-
OAUTH2_URL = 'https://www.box.com/api/oauth2'
10+
OAUTH2_API_URL = 'https://api.box.com/oauth2' # <https://developers.box.com/docs/#oauth-2>
11+
OAUTH2_AUTHORIZE_URL = 'https://app.box.com/api/oauth2/authorize' # <https://developers.box.com/docs/#oauth-2-authorize>

test/functional/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def mock_box(mock_box_server, monkeypatch, client_id, client_secret, user_name,
5050
mock_box_server.reset_filesystem([(user_name, user_login)], [(client_id, client_secret, 0)])
5151
monkeypatch.setattr(API, 'BASE_API_URL', 'http://localhost:{0}'.format(Box.API_PORT))
5252
monkeypatch.setattr(API, 'UPLOAD_URL', 'http://localhost:{0}'.format(Box.UPLOAD_PORT))
53-
monkeypatch.setattr(API, 'OAUTH2_URL', 'http://localhost:{0}'.format(Box.OAUTH_PORT))
53+
monkeypatch.setattr(API, 'OAUTH2_API_URL', 'http://localhost:{0}'.format(Box.OAUTH_API_PORT))
54+
monkeypatch.setattr(API, 'OAUTH2_AUTHORIZE_URL', 'http://localhost:{0}'.format(Box.OAUTH_AUTHORIZE_PORT))
5455
return mock_box_server
5556

5657

test/functional/mock_box/box.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ class Box(object):
4848
"""
4949
API_PORT = 8086
5050
UPLOAD_PORT = 8087
51-
OAUTH_PORT = 8088
51+
OAUTH_API_PORT = 8088
5252
EVENT_PORT = 8089
53+
OAUTH_AUTHORIZE_PORT = 8090
5354
RATE_LIMIT_THRESHOLD = 100
5455
RATE_LIMIT_REQUEST_PER_SECOND = 4
5556

@@ -60,12 +61,13 @@ def __init__(self):
6061
self._db_session_maker = None
6162
self.reset_filesystem()
6263
# Mock Box consists of 3 webservers - one for the content API, one for the upload API, and one for OAuth2
63-
api, upload, oauth, event = Bottle(), Bottle(), Bottle(), Bottle()
64+
api, upload, oauth_api, event, oauth_authorize = Bottle(), Bottle(), Bottle(), Bottle(), Bottle()
6465
app_mapping = {
6566
self.API_PORT: api,
6667
self.EVENT_PORT: event,
67-
self.OAUTH_PORT: oauth,
68+
self.OAUTH_API_PORT: oauth_api,
6869
self.UPLOAD_PORT: upload,
70+
self.OAUTH_AUTHORIZE_PORT: oauth_authorize,
6971
}
7072
# Since we don't instantiate the servers until Box is instantiated, we have to apply the routes now
7173
for routed_method in (getattr(self, m) for m in dir(self) if hasattr(getattr(self, m), 'route')):
@@ -77,8 +79,9 @@ def __init__(self):
7779
app.error(code)(self.handle_error)
7880
self._api = StoppableWSGIRefServer(host='localhost', port=self.API_PORT).run(api)
7981
self._upload = StoppableWSGIRefServer(host='localhost', port=self.UPLOAD_PORT).run(upload)
80-
self._oauth = StoppableWSGIRefServer(host='localhost', port=self.OAUTH_PORT).run(oauth)
82+
self._oauth_api = StoppableWSGIRefServer(host='localhost', port=self.OAUTH_API_PORT).run(oauth_api)
8183
self._event = StoppableWSGIRefServer(host='localhost', port=self.EVENT_PORT).run(event)
84+
self._oauth_authorize = StoppableWSGIRefServer(host='localhost', port=self.OAUTH_AUTHORIZE_PORT).run(oauth_authorize)
8285
self._rate_limit_bucket = (self.RATE_LIMIT_THRESHOLD, datetime.utcnow())
8386

8487
@staticmethod
@@ -90,10 +93,12 @@ def shutdown(self):
9093
"""Shutdown the webservers and wait for them to exit."""
9194
self._api.shutdown()
9295
self._upload.shutdown()
93-
self._oauth.shutdown()
96+
self._oauth_api.shutdown()
97+
self._oauth_authorize.shutdown()
9498
self._api.wait()
9599
self._upload.wait()
96-
self._oauth.wait()
100+
self._oauth_api.wait()
101+
self._oauth_authorize.wait()
97102

98103
def reset_filesystem(self, users=(), applications=()):
99104
"""
@@ -175,20 +180,20 @@ def append_to_request_log(self):
175180

176181
@log_request
177182
@allow_chaos
178-
@GET(OAUTH_PORT, '/authorize')
183+
@GET(OAUTH_AUTHORIZE_PORT, '/')
179184
@view('oauth2')
180185
def oauth2_authorize(self):
181186
return self._oauth_behavior.oauth2_authorize()
182187

183188
@log_request
184189
@allow_chaos
185-
@POST(OAUTH_PORT, '/authorize')
190+
@POST(OAUTH_AUTHORIZE_PORT, '/')
186191
def oauth2_finish_loop(self):
187192
return self._oauth_behavior.oauth2_finish_loop()
188193

189194
@log_request
190195
@allow_chaos
191-
@POST(OAUTH_PORT, '/token')
196+
@POST(OAUTH_API_PORT, '/token')
192197
def oauth2_token(self):
193198
return self._oauth_behavior.oauth2_token()
194199

test/integration/test_retry_and_refresh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_automatic_refresh(
2727
),
2828
call(
2929
'POST',
30-
'{0}/token'.format(API.OAUTH2_URL),
30+
'{0}/token'.format(API.OAUTH2_API_URL),
3131
data=ANY,
3232
headers={'content-type': 'application/x-www-form-urlencoded'},
3333
),

test/unit/auth/test_oauth2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def test_get_correct_authorization_url():
2222
)
2323
redirect_url = 'http://some.redirect.url.com'
2424
auth_url, csrf_token = oauth2.get_authorization_url(redirect_url)
25-
assert auth_url == '{0}/authorize?state={1}&response_type=code&client_id={2}&redirect_uri={3}'.format(
26-
API.OAUTH2_URL,
25+
assert auth_url == '{0}?state={1}&response_type=code&client_id={2}&redirect_uri={3}'.format(
26+
API.OAUTH2_AUTHORIZE_URL,
2727
csrf_token,
2828
fake_client_id,
2929
redirect_url,
@@ -55,7 +55,7 @@ def test_authenticate_send_post_request_with_correct_params(mock_network_layer,
5555

5656
mock_network_layer.request.assert_called_once_with(
5757
'POST',
58-
'{0}/token'.format(API.OAUTH2_URL),
58+
'{0}/token'.format(API.OAUTH2_API_URL),
5959
data=data,
6060
headers={'content-type': 'application/x-www-form-urlencoded'},
6161
access_token=None,
@@ -106,7 +106,7 @@ def test_refresh_send_post_request_with_correct_params_and_handles_multiple_requ
106106
# and it was made with the correct params.
107107
mock_network_layer.request.assert_called_once_with(
108108
'POST',
109-
'{0}/token'.format(API.OAUTH2_URL),
109+
'{0}/token'.format(API.OAUTH2_API_URL),
110110
data=data,
111111
headers={'content-type': 'application/x-www-form-urlencoded'},
112112
access_token=fake_access_token,

0 commit comments

Comments
 (0)