当前位置: 首页>>代码示例>>Python>>正文


Python Client._endpoint方法代码示例

本文整理汇总了Python中oic.oauth2.Client._endpoint方法的典型用法代码示例。如果您正苦于以下问题:Python Client._endpoint方法的具体用法?Python Client._endpoint怎么用?Python Client._endpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oic.oauth2.Client的用法示例。


在下文中一共展示了Client._endpoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_client_endpoint

# 需要导入模块: from oic.oauth2 import Client [as 别名]
# 或者: from oic.oauth2.Client import _endpoint [as 别名]
def test_client_endpoint():
    cli = Client()
    cli.authorization_endpoint = "https://example.org/oauth2/as"
    cli.token_endpoint = "https://example.org/oauth2/token"
    cli.token_revocation_endpoint = "https://example.org/oauth2/token_rev"

    ae = cli._endpoint("authorization_endpoint")
    assert ae == "https://example.org/oauth2/as"
    te = cli._endpoint("token_endpoint")
    assert te == "https://example.org/oauth2/token"
    tre = cli._endpoint("token_revocation_endpoint")
    assert tre == "https://example.org/oauth2/token_rev"

    ae = cli._endpoint("authorization_endpoint", **{"authorization_endpoint": "https://example.com/as"})
    assert ae == "https://example.com/as"

    cli.token_endpoint = ""
    raises(Exception, 'cli._endpoint("token_endpoint")')
    raises(Exception, 'cli._endpoint("foo_endpoint")')
开发者ID:asheidan,项目名称:pyoidc,代码行数:21,代码来源:test_oauth2.py

示例2: TestClient

# 需要导入模块: from oic.oauth2 import Client [as 别名]
# 或者: from oic.oauth2.Client import _endpoint [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()
#.........这里部分代码省略.........
开发者ID:joostd,项目名称:pyoidc,代码行数:103,代码来源:test_oauth2.py


注:本文中的oic.oauth2.Client._endpoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。