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


Python Client._parse_args方法代码示例

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


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

示例1: test_client_parse_extra_args

# 需要导入模块: from oic.oauth2 import Client [as 别名]
# 或者: from oic.oauth2.Client import _parse_args [as 别名]
def test_client_parse_extra_args():
    cli = Client()

    args = {
        "response_type": "",
        "client_id": "client_id",
        "redirect_uri": "http://example.com/authz",
        "scope": "scope",
        "state": "state",
        "extra_session": "home",
    }
    ar_args = cli._parse_args(AuthorizationRequest, **args)

    assert _eq(ar_args.keys(), ["state", "redirect_uri", "response_type", "client_id", "scope", "extra_session"])
开发者ID:asheidan,项目名称:pyoidc,代码行数:16,代码来源:test_oauth2.py

示例2: test_client_parse_args

# 需要导入模块: from oic.oauth2 import Client [as 别名]
# 或者: from oic.oauth2.Client import _parse_args [as 别名]
def test_client_parse_args():
    cli = Client()

    args = {
        "response_type": "",
        "client_id": "client_id",
        "redirect_uri": "http://example.com/authz",
        "scope": "scope",
        "state": "state",
    }

    ar_args = cli._parse_args(AuthorizationRequest, **args)

    assert _eq(ar_args.keys(), ['scope', 'state', 'redirect_uri',
                                'response_type', 'client_id'])
开发者ID:dajiaji,项目名称:pyoidc,代码行数:17,代码来源:test_oauth2.py

示例3: TestClient

# 需要导入模块: from oic.oauth2 import Client [as 别名]
# 或者: from oic.oauth2.Client import _parse_args [as 别名]

#.........这里部分代码省略.........
        grant = Grant(-10)  # expired grant
        grant.add_code(resp)

        client = Client()
        client.grant["openid"] = grant
        with pytest.raises(GrantExpired):
            client.construct_AccessTokenRequest(state="openid")

    def test_parse_access_token_resp_json(self):
        atr = self.client.parse_response(AccessTokenResponse, info=ACC_TOK_RESP.to_json())
        assert _eq(atr.keys(), ["token_type", "scope", "access_token", "refresh_token"])

    def test_parse_access_token_resp_urlencoded(self):
        uatr = self.client.parse_response(AccessTokenResponse, info=ACC_TOK_RESP.to_urlencoded(), sformat="urlencoded")
        assert _eq(uatr.keys(), ["token_type", "scope", "access_token", "refresh_token"])

    def test_parse_access_token_resp_url(self):
        url = "{}?{}".format("https://example.com/token", ACC_TOK_RESP.to_urlencoded())
        uatr = self.client.parse_response(AccessTokenResponse, info=url, sformat="urlencoded")
        assert _eq(uatr.keys(), ["token_type", "scope", "access_token", "refresh_token"])

    def test_parse_error_resp(self):
        err = ErrorResponse(
            error="invalid_request",
            error_description="Something was missing",
            error_uri="http://example.com/error_message.html",
        )
        jerr = err.to_json()
        uerr = err.to_urlencoded()

        _ = self.client.parse_response(AccessTokenResponse, info=jerr)
        _ = self.client.parse_response(AccessTokenResponse, info=uerr, sformat="urlencoded")

        with pytest.raises(ResponseError):
            self.client.parse_response(AccessTokenResponse, info=jerr, sformat="urlencoded")

        with pytest.raises(ValueError):
            self.client.parse_response(AccessTokenResponse, info=uerr)

        with pytest.raises(FormatError):
            self.client.parse_response(AccessTokenResponse, info=jerr, sformat="focus")

    def test_parse_access_token_resp_missing_attribute(self):
        atresp = AccessTokenResponse(
            access_token="SlAV32hkKG", token_type="Bearer", refresh_token="8xLOxBtZp8", expire_in=3600
        )
        atdict = atresp.to_dict()
        del atdict["access_token"]  # remove required access_token
        atj = json.dumps(atdict)

        with pytest.raises(MissingRequiredAttribute):
            self.client.parse_response(AccessTokenResponse, info=atj)

        with pytest.raises(MissingRequiredAttribute):
            self.client.parse_response(AccessTokenResponse, info=urlencode(atdict), sformat="urlencoded")

    def test_client_parse_args(self):
        args = {
            "response_type": "",
            "client_id": "client_id",
            "redirect_uri": "http://example.com/authz",
            "scope": "scope",
            "state": "state",
        }

        ar_args = self.client._parse_args(AuthorizationRequest, **args)

        assert _eq(ar_args.keys(), ["scope", "state", "redirect_uri", "response_type", "client_id"])

    def test_client_parse_extra_args(self):
        args = {
            "response_type": "",
            "client_id": "client_id",
            "redirect_uri": "http://example.com/authz",
            "scope": "scope",
            "state": "state",
            "extra_session": "home",
        }
        ar_args = self.client._parse_args(AuthorizationRequest, **args)

        assert _eq(ar_args.keys(), ["state", "redirect_uri", "response_type", "client_id", "scope", "extra_session"])

    def test_client_endpoint(self):
        self.client.authorization_endpoint = "https://example.org/oauth2/as"
        self.client.token_endpoint = "https://example.org/oauth2/token"
        self.client.token_revocation_endpoint = "https://example.org/oauth2/token_rev"

        assert self.client._endpoint("authorization_endpoint") == "https://example.org/oauth2/as"
        assert self.client._endpoint("token_endpoint") == "https://example.org/oauth2/token"
        assert self.client._endpoint("token_revocation_endpoint") == "https://example.org/oauth2/token_rev"

        auth_endpoint = self.client._endpoint(
            "authorization_endpoint", **{"authorization_endpoint": "https://example.com/as"}
        )
        assert auth_endpoint == "https://example.com/as"

        self.client.token_endpoint = ""
        with pytest.raises(MissingEndpoint):
            self.client._endpoint("token_endpoint")
            self.client._endpoint("foo_endpoint")
开发者ID:joostd,项目名称:pyoidc,代码行数:104,代码来源:test_oauth2.py


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