本文整理汇总了Python中oic.oauth2.Grant.add_code方法的典型用法代码示例。如果您正苦于以下问题:Python Grant.add_code方法的具体用法?Python Grant.add_code怎么用?Python Grant.add_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oic.oauth2.Grant
的用法示例。
在下文中一共展示了Grant.add_code方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_grant
# 需要导入模块: from oic.oauth2 import Grant [as 别名]
# 或者: from oic.oauth2.Grant import add_code [as 别名]
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"
示例2: test_grant_add_code
# 需要导入模块: from oic.oauth2 import Grant [as 别名]
# 或者: from oic.oauth2.Grant import add_code [as 别名]
def test_grant_add_code():
ar = AuthorizationResponse(code="code", state="state")
grant = Grant()
grant.add_code(ar)
assert grant
assert grant.code == "code"
示例3: test_bearer_body
# 需要导入模块: from oic.oauth2 import Grant [as 别名]
# 或者: from oic.oauth2.Grant import add_code [as 别名]
def test_bearer_body():
client = Client("A")
client.client_secret = "boarding pass"
request_args = {"access_token": "Sesame"}
cis = ResourceRequest()
http_args = BearerBody(client).construct(cis, request_args)
assert cis["access_token"] == "Sesame"
print http_args
assert http_args is None
# ----------
resp = AuthorizationResponse(code="code", state="state")
grant = Grant()
grant.add_code(resp)
atr = AccessTokenResponse(access_token="2YotnFZFEjr1zCsicMWpAA",
token_type="example",
refresh_token="tGzv3JOkF0XG5Qx2TlKWIA",
example_parameter="example_value",
scope=["inner", "outer"])
grant.add_token(atr)
client.grant["state"] = grant
cis = ResourceRequest()
http_args = BearerBody(client).construct(cis, {}, state="state",
scope="inner")
assert cis["access_token"] == "2YotnFZFEjr1zCsicMWpAA"
print http_args
assert http_args is None
示例4: test_grant_access_token_1
# 需要导入模块: from oic.oauth2 import Grant [as 别名]
# 或者: from oic.oauth2.Grant import add_code [as 别名]
def test_grant_access_token_1():
resp = AuthorizationResponse(code="code", state="state")
grant = Grant()
grant.add_code(resp)
atr = AccessTokenResponse(access_token="2YotnFZFEjr1zCsicMWpAA",
token_type="example", expires_in=1,
refresh_token="tGzv3JOkF0XG5Qx2TlKWIA",
example_parameter="example_value",
xscope=["inner", "outer"])
token = Token(atr)
grant.tokens.append(token)
print grant.keys()
assert _eq(grant.keys(), ['tokens', 'id_token', 'code', 'exp_in', 'seed',
'grant_expiration_time'])
print token.keys()
assert _eq(token.keys(), ['token_expiration_time', 'access_token',
'expires_in', 'example_parameter', 'token_type',
'xscope', 'refresh_token', 'scope',
'replaced'])
assert token.access_token == "2YotnFZFEjr1zCsicMWpAA"
assert token.token_type == "example"
assert token.refresh_token == "tGzv3JOkF0XG5Qx2TlKWIA"
assert token.example_parameter == "example_value"
assert token.xscope == ["inner", "outer"]
assert token.token_expiration_time != 0
time.sleep(2)
assert token.is_valid() is False
示例5: test_construct_access_token_req_expired_grant
# 需要导入模块: from oic.oauth2 import Grant [as 别名]
# 或者: from oic.oauth2.Grant import add_code [as 别名]
def test_construct_access_token_req_expired_grant(self):
resp = AuthorizationResponse(code="code", state="state")
grant = Grant(-10) # expired grant
grant.add_code(resp)
client = Client()
client.grant["openid"] = grant
with pytest.raises(GrantExpired):
client.construct_AccessTokenRequest(state="openid")
示例6: test_client_get_grant
# 需要导入模块: from oic.oauth2 import Grant [as 别名]
# 或者: from oic.oauth2.Grant import add_code [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"
示例7: test_get_access_token_request
# 需要导入模块: from oic.oauth2 import Grant [as 别名]
# 或者: from oic.oauth2.Grant import add_code [as 别名]
def test_get_access_token_request():
resp = AuthorizationResponse(code="code", state="state")
grant = Grant(1)
grant.add_code(resp)
client = Client()
client.grant["openid"] = grant
time.sleep(2)
try:
client.construct_AccessTokenRequest(state="openid")
except Exception, err:
assert err.__class__.__name__ == "GrantExpired"
示例8: test_grant_resp
# 需要导入模块: from oic.oauth2 import Grant [as 别名]
# 或者: from oic.oauth2.Grant import add_code [as 别名]
def test_grant_resp():
resp = AuthorizationResponse(code="code", state="state")
grant = Grant()
grant.add_code(resp)
assert grant.code == "code"
assert grant.grant_expiration_time != 0
grant = Grant(1)
grant.add_code(resp)
time.sleep(2)
assert grant.is_valid() is False
grant = Grant.from_code(resp)
assert grant.code == "code"
assert grant.grant_expiration_time != 0
示例9: test_grant_access_token_2
# 需要导入模块: from oic.oauth2 import Grant [as 别名]
# 或者: from oic.oauth2.Grant import add_code [as 别名]
def test_grant_access_token_2():
resp = AuthorizationResponse(code="code", state="state")
grant = Grant()
grant.add_code(resp)
atr = AccessTokenResponse(access_token="2YotnFZFEjr1zCsicMWpAA",
token_type="example",
refresh_token="tGzv3JOkF0XG5Qx2TlKWIA",
example_parameter="example_value",
scope=["inner", "outer"])
grant.add_token(atr)
assert len(grant.tokens) == 1
time.sleep(2)
token = grant.tokens[0]
assert token.is_valid() is True
assert "%s" % grant != ""