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


Python Client.grant_from_state方法代码示例

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


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

示例1: test_client_get_grant

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

    resp = AuthorizationResponse(code="code", state="state")
    grant = Grant()
    grant.add_code(resp)

    cli.grant["state"] = grant

    gr1 = cli.grant_from_state("state")

    assert gr1.code == "code"
开发者ID:dajiaji,项目名称:pyoidc,代码行数:14,代码来源:test_oauth2.py

示例2: TestClient

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

#.........这里部分代码省略.........
        atr = self.client.construct_RefreshAccessTokenRequest(token=token)

        assert atr["grant_type"] == "refresh_token"
        assert atr["refresh_token"] == "refresh_with_me"

    def test_get_access_token_refresh_from_state(self):
        self.client.grant["foo"] = Grant()
        _get = time_util.utc_time_sans_frac() + 60
        self.client.grant["foo"].grant_expiration_time = _get
        self.client.grant["foo"].code = "access_code"

        resp = AccessTokenResponse(refresh_token="refresh_with_me", access_token="access")

        self.client.grant["foo"].tokens.append(Token(resp))
        # Uses refresh_token from previous response
        atr = self.client.construct_RefreshAccessTokenRequest(state="foo")

        assert isinstance(atr, RefreshAccessTokenRequest)
        assert atr["grant_type"] == "refresh_token"
        assert atr["refresh_token"] == "refresh_with_me"

    def test_parse_authz_err_resp(self):
        error = "access_denied"
        state = "xyz"
        ruri = "{}?error={}&state={}".format(self.redirect_uri, error, state)

        resp = self.client.parse_response(AuthorizationResponse, info=ruri, sformat="urlencoded")

        assert isinstance(resp, AuthorizationErrorResponse)
        assert resp["error"] == error
        assert resp["state"] == state

    def test_return_non_existant_grant(self):
        assert self.client.grant_from_state("123456abcdef") is None

    def test_get_grant(self):
        resp = AuthorizationResponse(code="code", state="state")
        grant = Grant()
        grant.add_code(resp)

        self.client.grant["state"] = grant
        assert self.client.grant_from_state("state").code == "code"

    def test_construct_access_token_req_with_extra_args(self):
        query = "code=SplxlOBeZQQYbYS6WxSbIA&state=abc"
        self.client.parse_response(AuthorizationResponse, info=query, sformat="urlencoded")

        req = self.client.construct_AccessTokenRequest(state="abc", extra_args={"foo": "bar"})

        assert _eq(req.keys(), ["code", "grant_type", "client_id", "redirect_uri", "foo"])
        assert req["foo"] == "bar"

    def test_construct_TokenRevocationRequest(self):
        self.client.grant["foo"] = Grant()
        _get = time_util.utc_time_sans_frac() + 60
        self.client.grant["foo"].grant_expiration_time = _get
        self.client.grant["foo"].code = "access_code"
        resp = AccessTokenResponse(refresh_token="refresh_with_me", access_token="access")
        token = Token(resp)
        self.client.grant["foo"].tokens.append(token)

        state = "foo"
        query = "code=SplxlOBeZQQYbYS6WxSbIA&state={}".format(state)
        self.client.parse_response(AuthorizationResponse, info=query, sformat="urlencoded")

        req = self.client.construct_TokenRevocationRequest(state=state)
开发者ID:joostd,项目名称:pyoidc,代码行数:70,代码来源:test_oauth2.py

示例3: TestOAuthClient

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

#.........这里部分代码省略.........
        assert atr["refresh_token"] == "tGzv3JOkF0XG5Qx2TlKWIA"

    def test_get_access_token_refresh_2(self):
        self.client.grant["foo"] = Grant()
        _get = time_util.utc_time_sans_frac() + 60
        self.client.grant["foo"].grant_expiration_time = _get
        self.client.grant["foo"].code = "access_code"

        print self.client.grant["foo"]
        resp = AccessTokenResponse(refresh_token="refresh_with_me",
                                   access_token="access")

        self.client.grant["foo"].tokens.append(Token(resp))
        # Uses refresh_token from previous response
        atr = self.client.construct_RefreshAccessTokenRequest(state="foo")

        assert atr.type() == "RefreshAccessTokenRequest"
        assert atr["grant_type"] == "refresh_token"
        assert atr["refresh_token"] == "refresh_with_me"

    def test_parse_authz_err_response(self):
        ruri = "https://client.example.com/cb?error=access_denied&state=xyz"

        resp = self.client.parse_response(AuthorizationResponse,
                                          info=ruri, sformat="urlencoded")

        print type(resp), resp
        assert resp.type() == "AuthorizationErrorResponse"

        assert resp["error"] == "access_denied"
        assert resp["state"] == "xyz"

    def test_return_non_existant_grant(self):
        assert self.client.grant_from_state("123456abcdef") is None

    def test_construct_request_with_extra_args(self):
        print self.client.__dict__.items()
        req = self.client.construct_AccessTokenRequest(
            state="foo", extra_args={"foo": "bar"})

        assert req
        print req.keys()
        assert _eq(req.keys(), ['code', 'grant_type', 'client_id',
                                'redirect_uri', 'foo'])
        assert req["foo"] == "bar"

    def test_construct_TokenRevocationRequest(self):
        req = self.client.construct_TokenRevocationRequest(state="foo")

        assert req
        print req.keys()
        assert _eq(req.keys(), ['token'])
        assert req["token"] == "access"

    def test_request_info_simple(self):
        self.client.authorization_endpoint = "https://example.com/authz"
        uri, body, h_args, cis = self.client.request_info(AuthorizationRequest)

        # default == "POST"
        assert uri == 'https://example.com/authz'
        assert body == "redirect_uri=http%3A%2F%2Fclient.example.com%2Fauthz&response_type=code&client_id=1"
        assert h_args == {'headers': {'content-type':
                                          'application/x-www-form-urlencoded'}}
        assert cis.type() == "AuthorizationRequest"

    def test_request_info_simple_get(self):
开发者ID:dajiaji,项目名称:pyoidc,代码行数:70,代码来源:test_oauth2.py


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