本文整理汇总了Python中oic.oauth2.Client.construct_RefreshAccessTokenRequest方法的典型用法代码示例。如果您正苦于以下问题:Python Client.construct_RefreshAccessTokenRequest方法的具体用法?Python Client.construct_RefreshAccessTokenRequest怎么用?Python Client.construct_RefreshAccessTokenRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oic.oauth2.Client
的用法示例。
在下文中一共展示了Client.construct_RefreshAccessTokenRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestClient
# 需要导入模块: from oic.oauth2 import Client [as 别名]
# 或者: from oic.oauth2.Client import construct_RefreshAccessTokenRequest [as 别名]
#.........这里部分代码省略.........
def test_parse_access_token_resp(self):
atr = AccessTokenResponse(
access_token="2YotnFZFEjr1zCsicMWpAA",
token_type="example",
expires_in=3600,
refresh_token="tGzv3JOkF0XG5Qx2TlKWIA",
example_parameter="example_value",
)
self.client.parse_response(AccessTokenResponse, info=json.dumps(atr.to_dict()))
_grant = self.client.grant[""]
assert len(_grant.tokens) == 1
token = _grant.tokens[0]
assert token.access_token == "2YotnFZFEjr1zCsicMWpAA"
assert token.token_type == "example"
assert token.expires_in == 3600
assert token.refresh_token == "tGzv3JOkF0XG5Qx2TlKWIA"
# I'm dropping parameters I don't recognize
# with pytest.raises(AttributeError): # TODO not satisfied
# nothing = token.example_parameter
def test_get_access_token_refresh_with_refresh_token(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)
# Uses refresh_token from previous response
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):
示例2: TestOAuthClient
# 需要导入模块: from oic.oauth2 import Client [as 别名]
# 或者: from oic.oauth2.Client import construct_RefreshAccessTokenRequest [as 别名]
#.........这里部分代码省略.........
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"token_type":"example",
"expires_in":3600,
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter":"example_value"
}"""
self.client.parse_response(AccessTokenResponse,
info="".join([
x.strip() for x in jso.split("\n")]))
assert self.client.grant
_grant = self.client.grant[""]
assert len(_grant.tokens) == 1
token = _grant.tokens[0]
assert token.access_token == "2YotnFZFEjr1zCsicMWpAA"
assert token.token_type == "example"
assert token.expires_in == 3600
assert token.refresh_token == "tGzv3JOkF0XG5Qx2TlKWIA"
# I'm dropping parameters I don't recognize
assert "example_parameter" not in self.client.__dict__
#assert self.client.access_token_is_valid()
def test_get_access_token_refresh_1(self):
print self.client.grant
self.client.grant[""].grant_expiration_time = time.time() + 60
self.client.grant[""].code = "access_code"
token = self.client.grant[""].tokens[0]
print token
# Uses refresh_token from previous response
atr = self.client.construct_RefreshAccessTokenRequest(token=token)
print atr.to_dict()
assert atr.type() == "RefreshAccessTokenRequest"
assert atr["grant_type"] == "refresh_token"
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"