本文整理汇总了Python中oic.oauth2.Client.construct_AuthorizationRequest方法的典型用法代码示例。如果您正苦于以下问题:Python Client.construct_AuthorizationRequest方法的具体用法?Python Client.construct_AuthorizationRequest怎么用?Python Client.construct_AuthorizationRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oic.oauth2.Client
的用法示例。
在下文中一共展示了Client.construct_AuthorizationRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_authorization_request
# 需要导入模块: from oic.oauth2 import Client [as 别名]
# 或者: from oic.oauth2.Client import construct_AuthorizationRequest [as 别名]
def test_get_authorization_request():
client = Client()
client.redirect_uris = ["https://www.example.com/authz"]
client.client_id = "a1b2c3"
args = {"response_type": ["code"]}
ar = client.construct_AuthorizationRequest(request_args=args)
assert ar["client_id"] == "a1b2c3"
assert ar["redirect_uri"] == "https://www.example.com/authz"
assert ar["response_type"] == ["code"]
client = Client()
client.client_id = "a1b2c3"
args = {"response_type": ["code"], "redirect_uri": "https://www.example.com/authz"}
ar = client.construct_AuthorizationRequest(request_args=args)
assert ar["client_id"] == "a1b2c3"
assert ar["redirect_uri"] == "https://www.example.com/authz"
assert ar["response_type"] == ["code"]
示例2: TestClient
# 需要导入模块: from oic.oauth2 import Client [as 别名]
# 或者: from oic.oauth2.Client import construct_AuthorizationRequest [as 别名]
class TestClient(object):
@pytest.fixture(autouse=True)
def create_client(self):
self.redirect_uri = "https://example.com/redirect"
self.authorization_endpoint = "https://example.com/authz"
self.client = Client("1") # pylint: disable=attribute-defined-outside-init
self.client.redirect_uris = [self.redirect_uri]
self.client.response_type = "code"
self.client.authorization_endpoint = self.authorization_endpoint
def test_construct_authz_req_no_optional_params(self):
areq = self.client.construct_AuthorizationRequest(request_args={"response_type": ["code"]})
assert areq["redirect_uri"] == self.redirect_uri
assert areq["response_type"] == ["code"]
assert areq["client_id"] == "1"
assert "state" not in areq
assert "scope" not in areq
def test_construct_authz_req_no_input(self):
self.client.response_type = ["code"]
atr = self.client.construct_AuthorizationRequest()
assert atr["redirect_uri"] == self.redirect_uri
assert atr["response_type"] == ["code"]
assert atr["client_id"] == "1"
def test_construct_authz_req_optional_params(self):
req_args = {"response_type": ["code"], "scope": ["foo", "bar"], "state": "abc"}
areq = self.client.construct_AuthorizationRequest(request_args=req_args)
assert areq["redirect_uri"] == self.redirect_uri
assert areq["response_type"] == ["code"]
assert areq["client_id"] == "1"
assert areq["state"] == "abc"
assert areq["scope"] == ["foo", "bar"]
def test_construct_authz_req_replace_default_state(self):
req_args = {"response_type": ["code"], "scope": ["foo", "bar"], "state": "efg"}
areq = self.client.construct_AuthorizationRequest(request_args=req_args)
assert areq["redirect_uri"] == self.redirect_uri
assert areq["response_type"] == ["code"]
assert areq["client_id"] == "1"
assert areq["state"] == "efg"
assert areq["scope"] == ["foo", "bar"]
def test_parse_authz_resp_url(self):
code = "SplxlOBeZQQYbYS6WxSbIA"
state = "ghi"
url = "{}?code={}&state={}".format(self.redirect_uri, code, state)
aresp = self.client.parse_response(AuthorizationResponse, info=url, sformat="urlencoded")
assert aresp["code"] == code
assert aresp["state"] == state
assert self.client.grant[state].code == aresp["code"]
assert self.client.grant[state].grant_expiration_time
def test_parse_authz_resp_query(self):
query = "code=SplxlOBeZQQYbYS6WxSbIA&state=hij"
aresp = self.client.parse_response(AuthorizationResponse, info=query, sformat="urlencoded")
assert aresp["code"] == "SplxlOBeZQQYbYS6WxSbIA"
assert aresp["state"] == "hij"
assert self.client.grant["hij"]
assert self.client.grant["hij"].code == aresp["code"]
assert self.client.grant["hij"].grant_expiration_time
def test_parse_authz_resp_query_multi_scope(self):
code = "SplxlOBeZQQYbYS6WxSbIA"
states = ["ghi", "hij", "klm"]
for state in states:
self.client.parse_response(
AuthorizationResponse, info="code={}&state={}".format(code, state), sformat="urlencoded"
)
for state in states:
assert self.client.grant[state].code == code
assert _eq(self.client.grant.keys(), states)
def test_parse_authz_resp_query_unknown_parameter(self):
query = "code=SplxlOBeZQQYbYS6WxSbIA&state=xyz&foo=bar"
aresp = self.client.parse_response(AuthorizationResponse, info=query, sformat="urlencoded")
assert aresp["code"] == "SplxlOBeZQQYbYS6WxSbIA"
assert aresp["state"] == "xyz"
# assert "foo" not in aresp # TODO unknown parameter not discarded
assert self.client.grant["xyz"]
assert self.client.grant["xyz"].code == aresp["code"]
assert self.client.grant["xyz"].grant_expiration_time
def test_construct_access_token_req(self):
grant = Grant()
#.........这里部分代码省略.........
示例3: TestOAuthClient
# 需要导入模块: from oic.oauth2 import Client [as 别名]
# 或者: from oic.oauth2.Client import construct_AuthorizationRequest [as 别名]
class TestOAuthClient():
def setup_class(self):
self.client = Client("1")
self.client.redirect_uris = ["http://example.com/redirect"]
def test_areq_1(self):
ar = self.client.construct_AuthorizationRequest(
request_args={"response_type": ["code"]})
assert ar["redirect_uri"] == "http://example.com/redirect"
assert ar["response_type"] == ["code"]
assert ar["client_id"] == "1"
assert "state" not in ar
assert "scope" not in ar
def test_areq_2(self):
self.client.state = "abc"
req_args = {"response_type": ["code"], "scope": ["foo", "bar"]}
ar = self.client.construct_AuthorizationRequest(request_args=req_args)
assert ar["redirect_uri"] == "http://example.com/redirect"
assert ar["response_type"] == ["code"]
assert ar["client_id"] == "1"
assert ar["state"] == "abc"
assert ar["scope"] == ["foo", "bar"]
def test_areq_replace_default_state(self):
self.client.state = "efg"
req_args = {"response_type": ["code"], "scope": ["foo", "bar"]}
ar = self.client.construct_AuthorizationRequest(request_args=req_args)
assert ar["redirect_uri"] == "http://example.com/redirect"
assert ar["response_type"] == ["code"]
assert ar["client_id"] == "1"
assert ar["state"] == "efg"
assert ar["scope"] == ["foo", "bar"]
def test_parse_authz_resp_url(self):
url = "https://client.example.com/cb?code=SplxlOBeZQQYbYS6WxSbIA&state=ghi"
aresp = self.client.parse_response(AuthorizationResponse,
info=url, sformat="urlencoded")
assert aresp["code"] == "SplxlOBeZQQYbYS6WxSbIA"
assert aresp["state"] == "ghi"
assert self.client.grant["ghi"]
assert self.client.grant["ghi"].code == aresp["code"]
assert self.client.grant["ghi"].grant_expiration_time
def test_parse_authz_resp_query(self):
query = "code=SplxlOBeZQQYbYS6WxSbIA&state=hij"
aresp = self.client.parse_response(AuthorizationResponse,
info=query, sformat="urlencoded")
assert aresp["code"] == "SplxlOBeZQQYbYS6WxSbIA"
assert aresp["state"] == "hij"
print self.client.grant.keys()
assert self.client.grant["hij"]
assert self.client.grant["hij"].code == aresp["code"]
assert self.client.grant["hij"].grant_expiration_time
def test_parse_authz_resp_query_multi_scope(self):
query = "code=SplxlOBeZQQYbYS6WxAAAA&state=klm"
aresp = self.client.parse_response(AuthorizationResponse,
info=query, sformat="urlencoded")
assert aresp["code"] == "SplxlOBeZQQYbYS6WxAAAA"
assert aresp["state"] == "klm"
assert self.client.grant["klm"]
assert self.client.grant["klm"].code == aresp["code"]
assert self.client.grant["klm"].grant_expiration_time
assert _eq(self.client.grant.keys(), ['ghi', 'hij', 'klm'])
def test_parse_authz_resp_query_unknown_parameter(self):
query = "code=SplxlOBeZQQYbYS6WxSbIA&state=xyz&foo=bar"
aresp = self.client.parse_response(AuthorizationResponse,
info=query, sformat="urlencoded")
assert aresp["code"] == "SplxlOBeZQQYbYS6WxSbIA"
assert aresp["state"] == "xyz"
print aresp.__dict__.keys()
assert "foo" not in aresp.__dict__
assert self.client.grant["xyz"]
assert self.client.grant["xyz"].code == aresp["code"]
assert self.client.grant["xyz"].grant_expiration_time
def test_get_access_token_request_1(self):
self.client.reset()
self.client.redirect_uris = ["http://client.example.com/authz"]
grant = Grant()
grant.code = "AbCdEf"
grant.grant_expiration_time = time_util.utc_time_sans_frac() + 30
self.client.grant = {"stat": grant}
# scope is default=""
#.........这里部分代码省略.........