本文整理汇总了Python中oic.oauth2.message.AccessTokenRequest.to_urlencoded方法的典型用法代码示例。如果您正苦于以下问题:Python AccessTokenRequest.to_urlencoded方法的具体用法?Python AccessTokenRequest.to_urlencoded怎么用?Python AccessTokenRequest.to_urlencoded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oic.oauth2.message.AccessTokenRequest
的用法示例。
在下文中一共展示了AccessTokenRequest.to_urlencoded方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_token_endpoint_unauth
# 需要导入模块: from oic.oauth2.message import AccessTokenRequest [as 别名]
# 或者: from oic.oauth2.message.AccessTokenRequest import to_urlencoded [as 别名]
def test_token_endpoint_unauth(self):
authreq = AuthorizationRequest(state="state",
redirect_uri="http://example.com/authz",
client_id="client1")
_sdb = self.provider.sdb
sid = _sdb.access_token.key(user="sub", areq=authreq)
access_grant = _sdb.access_token(sid=sid)
_sdb[sid] = {
"oauth_state": "authz",
"sub": "sub",
"authzreq": "",
"client_id": "client1",
"code": access_grant,
"code_used": False,
"redirect_uri": "http://example.com/authz"
}
# Construct Access token request
areq = AccessTokenRequest(code=access_grant,
redirect_uri="http://example.com/authz",
client_id="client2",
client_secret="hemlighet",
grant_type='authorization_code')
resp = self.provider.token_endpoint(request=areq.to_urlencoded())
atr = TokenErrorResponse().deserialize(resp.message, "json")
assert _eq(atr.keys(), ['error_description', 'error'])
示例2: test_token_endpoint_unauth
# 需要导入模块: from oic.oauth2.message import AccessTokenRequest [as 别名]
# 或者: from oic.oauth2.message.AccessTokenRequest import to_urlencoded [as 别名]
def test_token_endpoint_unauth():
provider = Provider("pyoicserv", sdb.SessionDB(), CDB, AUTHN_BROKER, AUTHZ,
verify_client, symkey=rndstr(16))
authreq = AuthorizationRequest(state="state",
redirect_uri="http://example.com/authz",
client_id="client1")
_sdb = provider.sdb
sid = _sdb.token.key(user="user_id", areq=authreq)
access_grant = _sdb.token(sid=sid)
_sdb[sid] = {
"oauth_state": "authz",
"user_id": "user_id",
"authzreq": "",
"client_id": "client1",
"code": access_grant,
"code_used": False,
"redirect_uri": "http://example.com/authz"
}
# Construct Access token request
areq = AccessTokenRequest(code=access_grant,
redirect_uri="http://example.com/authz",
client_id="client2", client_secret="hemlighet",)
print areq.to_dict()
resp = provider.token_endpoint(request=areq.to_urlencoded())
print resp.message
atr = TokenErrorResponse().deserialize(resp.message, "json")
print atr.keys()
assert _eq(atr.keys(), ['error_description', 'error'])
示例3: test_token_introspection
# 需要导入模块: from oic.oauth2.message import AccessTokenRequest [as 别名]
# 或者: from oic.oauth2.message.AccessTokenRequest import to_urlencoded [as 别名]
def test_token_introspection(self):
authreq = AuthorizationRequest(state="state", redirect_uri="http://example.com/authz", client_id="client1")
_sdb = self.provider.sdb
sid = _sdb.access_token.key(user="sub", areq=authreq)
access_grant = _sdb.token_factory["code"](sid=sid)
_sdb[sid] = {
"oauth_state": "authz",
"sub": "sub",
"authzreq": authreq.to_json(),
"client_id": "client1",
"code": access_grant,
"code_used": False,
"redirect_uri": "http://example.com/authz",
"response_type": ["code"],
}
# Construct Access token request
areq = AccessTokenRequest(
code=access_grant,
redirect_uri="http://example.com/authz",
client_id="client1",
client_secret="hemlighet",
grant_type="authorization_code",
)
resp = self.provider.token_endpoint(request=areq.to_urlencoded())
atr = AccessTokenResponse().deserialize(resp.message, "json")
req = TokenIntrospectionRequest(
token=atr["access_token"], client_id="client1", client_secret="hemlighet", token_type_hint="access_token"
)
resp = self.provider.introspection_endpoint(request=req.to_urlencoded())
assert resp
ti_resp = TokenIntrospectionResponse().deserialize(resp.message, "json")
assert ti_resp["active"] is True
示例4: test_extra
# 需要导入模块: from oic.oauth2.message import AccessTokenRequest [as 别名]
# 或者: from oic.oauth2.message.AccessTokenRequest import to_urlencoded [as 别名]
def test_extra(self):
atr = AccessTokenRequest(grant_type="authorization_code",
code="SplxlOBeZQQYbYS6WxSbIA",
redirect_uri="https://client.example.com/cb",
extra="foo")
query = atr.to_urlencoded()
assert query_string_compare(query,
"code=SplxlOBeZQQYbYS6WxSbIA&redirect_uri=https%3A%2F%2Fclient.example.com%2Fcb&grant_type=authorization_code&extra=foo")
atr2 = AccessTokenRequest().deserialize(query, "urlencoded")
assert atr == atr2
示例5: test_server_parse_token_request
# 需要导入模块: from oic.oauth2.message import AccessTokenRequest [as 别名]
# 或者: from oic.oauth2.message.AccessTokenRequest import to_urlencoded [as 别名]
def test_server_parse_token_request(self):
atr = AccessTokenRequest(
grant_type="authorization_code", code="SplxlOBeZQQYbYS6WxSbIA",
redirect_uri="https://client.example.com/cb", extra="foo")
uenc = atr.to_urlencoded()
tr = self.srv.parse_token_request(body=uenc)
assert isinstance(tr, AccessTokenRequest)
assert _eq(tr.keys(), ['code', 'redirect_uri', 'grant_type', 'extra'])
assert tr["grant_type"] == "authorization_code"
assert tr["code"] == "SplxlOBeZQQYbYS6WxSbIA"
tr = self.srv.parse_token_request(body=uenc)
assert isinstance(tr, AccessTokenRequest)
assert _eq(tr.keys(), ['code', 'grant_type', 'redirect_uri', 'extra'])
assert tr["extra"] == "foo"
示例6: test_token_endpoint
# 需要导入模块: from oic.oauth2.message import AccessTokenRequest [as 别名]
# 或者: from oic.oauth2.message.AccessTokenRequest import to_urlencoded [as 别名]
def test_token_endpoint():
provider = Provider("pyoicserv", sdb.SessionDB(), CDB, FUNCTIONS)
authreq = AuthorizationRequest(state="state",
redirect_uri="http://example.com/authz",
client_id="client1")
_sdb = provider.sdb
sid = _sdb.token.key(user="user_id", areq=authreq)
access_grant = _sdb.token(sid=sid)
_sdb[sid] = {
"oauth_state": "authz",
"user_id": "user_id",
"authzreq": "",
"client_id": "client1",
"code": access_grant,
"code_used": False,
"redirect_uri":"http://example.com/authz"
}
# Construct Access token request
areq = AccessTokenRequest(code=access_grant,
redirect_uri="http://example.com/authz")
str = areq.to_urlencoded()
fil = StringIO.StringIO(buf=str)
environ = BASE_ENVIRON.copy()
environ["CONTENT_LENGTH"] = len(str)
environ["wsgi.input"] = fil
environ["REMOTE_USER"] = "client1"
resp = provider.token_endpoint(environ, start_response)
print resp
atr = AccessTokenResponse().deserialize(resp[0], "json")
print atr.keys()
assert _eq(atr.keys(), ['access_token', 'expires_in', 'token_type',
'refresh_token'])