def test_oauth2_start_flow_default(self):
"""
Starts a default GlobusAuthorizationCodeFlowManager,
Confirms flow is initialized as expected, and can be used.
"""
# starting with no flow
self.assertIsNone(self.cac.current_oauth2_flow_manager)
# confirms flow initialized with default flow values
flow = self.cac.oauth2_start_flow("uri")
self.assertIsInstance(flow, GlobusAuthorizationCodeFlowManager)
self.assertEqual(flow.redirect_uri, "uri")
self.assertEqual(flow.requested_scopes,
" ".join(DEFAULT_REQUESTED_SCOPES))
self.assertEqual(flow.state, "_default")
self.assertFalse(flow.refresh_tokens)
# confirm client can get url via flow
url_res = self.cac.oauth2_get_authorize_url()
expected_vals = [self.cac.base_url + "v2/oauth2/authorize?",
"client_id=" + self.cac.client_id,
"redirect_uri=" + "uri",
"scope=" + quote_plus(
" ".join(DEFAULT_REQUESTED_SCOPES)),
"state=" + "_default",
"access_type=" + "online"]
for val in expected_vals:
self.assertIn(val, url_res)
# confirm client can try exchanging code for tokens via flow
with self.assertRaises(AuthAPIError) as apiErr:
self.cac.oauth2_exchange_code_for_tokens("invalid_code")
self.assertEqual(apiErr.exception.http_status, 401)
self.assertEqual(apiErr.exception.code, "Error")
test_confidential_client_flow.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录