本文整理汇总了Python中oic.oauth2.consumer.Consumer.begin方法的典型用法代码示例。如果您正苦于以下问题:Python Consumer.begin方法的具体用法?Python Consumer.begin怎么用?Python Consumer.begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oic.oauth2.consumer.Consumer
的用法示例。
在下文中一共展示了Consumer.begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_provider_authenticated
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_provider_authenticated():
provider = Provider("pyoicserv", sdb.SessionDB(), CDB, AUTHN_BROKER, AUTHZ,
verify_client, symkey=rndstr(16))
_session_db = {}
cons = Consumer(_session_db, client_config=CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
location = cons.begin("http://localhost:8087",
"http://localhost:8088/authorization")
query_string = location.split("?")[1]
resp = provider.authorization_endpoint(query_string)
assert resp.status == "302 Found"
print resp.headers
print resp.message
if content_type(resp.headers) == "json":
resp = resp.message
else:
resp = resp.message.split("?")[1]
aresp = cons.handle_authorization_response(query=resp)
print aresp.keys()
assert aresp.type() == "AuthorizationResponse"
assert _eq(aresp.keys(), ['state', 'code'])
print cons.grant[cons.state].keys()
assert _eq(cons.grant[cons.state].keys(), ['tokens', 'code', 'exp_in',
'seed', 'id_token',
'grant_expiration_time'])
示例2: test_provider_authenticated_none
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_provider_authenticated_none():
provider = Provider("pyoicserv", sdb.SessionDB(), CDB, FUNCTIONS)
_session_db = {}
cons = Consumer(_session_db, client_config = CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
cons.response_type = "none"
environ = BASE_ENVIRON
location = cons.begin(environ, start_response)
environ = BASE_ENVIRON.copy()
environ["QUERY_STRING"] = location.split("?")[1]
resp = provider.authorization_endpoint(environ, start_response)
sid = resp[0][len("FORM with "):]
environ2 = create_return_form_env("user", "password", sid)
resp2 = provider.authenticated(environ2, start_response)
assert len(resp2) == 1
txt = resp2[0]
pos0 = txt.index("<title>") + len("<title>Redirecting to ")
pos1 = txt.index("</title>")
location = txt[pos0:pos1]
print location
assert location.startswith("http://localhost:8087/authz")
query = location.split("?")[1]
assert query.startswith("state=")
assert "&" not in query
示例3: test_consumer_parse_access_token
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_consumer_parse_access_token():
# implicit flow test
_session_db = {}
cons = Consumer(_session_db, client_config=CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
environ = BASE_ENVIRON
cons.response_type = ["token"]
sid, loc = cons.begin("http://localhost:8087",
"http://localhost:8088/authorization")
atr = AccessTokenResponse(access_token="2YotnFZFEjr1zCsicMWpAA",
token_type="example",
refresh_token="tGzv3JOkF0XG5Qx2TlKWIA",
example_parameter="example_value",
state=sid)
res = cons.handle_authorization_response(query=atr.to_urlencoded())
assert res.type() == "AccessTokenResponse"
print cons.grant[sid]
grant = cons.grant[sid]
assert len(grant.tokens) == 1
token = grant.tokens[0]
assert token.access_token == "2YotnFZFEjr1zCsicMWpAA"
示例4: test_consumer_parse_access_token
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_consumer_parse_access_token():
# implicit flow test
_session_db = {}
cons = Consumer(_session_db, client_config = CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
environ = BASE_ENVIRON
cons.response_type = ["token"]
_ = cons.begin(environ, start_response)
atr = AccessTokenResponse(access_token="2YotnFZFEjr1zCsicMWpAA",
token_type="example",
refresh_token="tGzv3JOkF0XG5Qx2TlKWIA",
example_parameter="example_value",
state=cons.state)
environ = BASE_ENVIRON.copy()
environ["QUERY_STRING"] = atr.to_urlencoded()
res = cons.handle_authorization_response(environ, start_response)
assert res.type() == "AccessTokenResponse"
print cons.grant[cons.state]
grant = cons.grant[cons.state]
assert len(grant.tokens) == 1
token = grant.tokens[0]
assert token.access_token == "2YotnFZFEjr1zCsicMWpAA"
示例5: test_provider_authenticated_token
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_provider_authenticated_token():
provider = Provider("pyoicserv", sdb.SessionDB(), CDB, FUNCTIONS)
_session_db = {}
cons = Consumer(_session_db, client_config = CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
cons.response_type = "token"
environ = BASE_ENVIRON
location = cons.begin(environ, start_response)
environ = BASE_ENVIRON.copy()
environ["QUERY_STRING"] = location.split("?")[1]
resp = provider.authorization_endpoint(environ, start_response)
sid = resp[0][len("FORM with "):]
environ2 = create_return_form_env("user", "password", sid)
resp2 = provider.authenticated(environ2, start_response)
assert len(resp2) == 1
txt = resp2[0]
assert "access_token=" in txt
assert "token_type=Bearer" in txt
示例6: test_authenticated_token
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_authenticated_token(self):
_session_db = {}
cons = Consumer(_session_db, client_config=CLIENT_CONFIG, server_info=SERVER_INFO, **CONSUMER_CONFIG)
sid, location = cons.begin("http://localhost:8087", "http://localhost:8088/authorization", "token")
QUERY_STRING = location.split("?")[1]
resp = self.provider.authorization_endpoint(QUERY_STRING)
auth_resp = parse_qs(urlparse(resp.message).fragment)
assert "access_token" in auth_resp
assert auth_resp["token_type"][0] == "Bearer"
示例7: test_authenticated
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_authenticated(self):
_session_db = {}
cons = Consumer(_session_db, client_config=CLIENT_CONFIG, server_info=SERVER_INFO, **CONSUMER_CONFIG)
sid, location = cons.begin("http://localhost:8087", "http://localhost:8088/authorization")
resp = self.provider.authorization_endpoint(urlparse(location).query)
assert resp.status == "302 Found"
resp = urlparse(resp.message).query
aresp = cons.handle_authorization_response(query=resp)
assert isinstance(aresp, AuthorizationResponse)
assert _eq(aresp.keys(), ["state", "code"])
assert _eq(cons.grant[sid].keys(), ["tokens", "code", "exp_in", "seed", "id_token", "grant_expiration_time"])
示例8: test_consumer_parse_authz_error_2
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_consumer_parse_authz_error_2():
_session_db = {}
cons = Consumer(_session_db, client_config=CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
_ = cons.begin("http://localhost:8087",
"http://localhost:8088/authorization")
atr = TokenErrorResponse(error="invalid_client")
QUERY_STRING = atr.to_urlencoded()
raises(AuthzError,
"cons.handle_authorization_response(query=QUERY_STRING)")
示例9: test_provider_authenticated_token
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_provider_authenticated_token():
provider = Provider("pyoicserv", sdb.SessionDB(), CDB, AUTHN_BROKER, AUTHZ, verify_client)
_session_db = {}
cons = Consumer(_session_db, client_config=CLIENT_CONFIG, server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
location = cons.begin("http://localhost:8087", "http://localhost:8088/authorization", "token")
QUERY_STRING = location.split("?")[1]
resp = provider.authorization_endpoint(QUERY_STRING)
print resp.headers
print resp.message
txt = resp.message
assert "access_token=" in txt
assert "token_type=Bearer" in txt
示例10: register
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def register(environ, start_response, logger, kaka=None):
"""
Initialize the OAuth2 flow
"""
_session_db = environ["oic.sessiondb"]
_cc = environ["oic.client_config"]
_conc = environ["oic.consumer.config"]
_server_info = environ["oic.server.info"]
# get the redirect to the authorization server endpoint
_oac = Consumer(_session_db, _conc, _cc, _server_info)
location = _oac.begin(environ, start_response, logger)
resp = http_util.Redirect(location)
return resp(environ, start_response)
示例11: test_consumer_parse_authz_error_2
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_consumer_parse_authz_error_2():
_session_db = {}
cons = Consumer(_session_db, client_config = CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
environ = BASE_ENVIRON
_ = cons.begin(environ, start_response)
atr = TokenErrorResponse(error="invalid_client")
environ = BASE_ENVIRON.copy()
environ["QUERY_STRING"] = atr.to_urlencoded()
raises(AuthzError,
"cons.handle_authorization_response(environ, start_response)")
示例12: test_provider_authenticated
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_provider_authenticated():
provider = Provider("pyoicserv", sdb.SessionDB(), CDB, FUNCTIONS)
_session_db = {}
cons = Consumer(_session_db, client_config = CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
environ = BASE_ENVIRON
location = cons.begin(environ, start_response)
environ = BASE_ENVIRON.copy()
environ["QUERY_STRING"] = location.split("?")[1]
resp = provider.authorization_endpoint(environ, start_response)
sid = resp[0][len("FORM with "):]
environ2 = create_return_form_env("user", "password", sid)
resp2 = provider.authenticated(environ2, start_response)
print resp2[0]
assert len(resp2) == 1
txt = resp2[0]
pos0 = txt.index("<title>") + len("<title>Redirecting to ")
pos1 = txt.index("</title>")
location = txt[pos0:pos1]
print location
assert location.startswith("http://localhost:8087/authz")
environ = BASE_ENVIRON.copy()
environ["QUERY_STRING"] = location.split("?")[1]
aresp = cons.handle_authorization_response(environ, start_response)
#aresp = client.parse_response(AuthorizationResponse, location,
# format="urlencoded",
# state="id-6da9ca0cc23959f5f33e8becd9b08cae")
print aresp.keys()
assert aresp.type() == "AuthorizationResponse"
assert _eq(aresp.keys(), ['state', 'code'])
print cons.grant[cons.state].keys()
assert _eq(cons.grant[cons.state].keys(), ['tokens', 'code', 'exp_in',
'seed', 'id_token',
'grant_expiration_time'])
示例13: test_consumer_handle_authorization_response
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_consumer_handle_authorization_response():
_session_db = {}
cons = Consumer(_session_db, client_config=CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
sid, loc = cons.begin("http://localhost:8087",
"http://localhost:8088/authorization")
atr = AuthorizationResponse(code="SplxlOBeZQQYbYS6WxSbIA",
state=sid)
res = cons.handle_authorization_response(query=atr.to_urlencoded())
assert res.type() == "AuthorizationResponse"
print cons.grant[sid]
grant = cons.grant[sid]
assert grant.code == "SplxlOBeZQQYbYS6WxSbIA"
示例14: test_consumer_begin
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_consumer_begin():
_session_db = {}
cons = Consumer(_session_db, client_config=CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
sid, loc = cons.begin("http://localhost:8087",
"http://localhost:8088/authorization")
# state is dynamic
params = {"scope": "openid",
"state": sid,
"redirect_uri": "http://localhost:8087/authz",
"response_type": "code",
"client_id": "number5"}
url = "http://localhost:8088/authorization?%s" % urllib.urlencode(params)
assert loc == url
示例15: test_consumer_parse_authz_exception
# 需要导入模块: from oic.oauth2.consumer import Consumer [as 别名]
# 或者: from oic.oauth2.consumer.Consumer import begin [as 别名]
def test_consumer_parse_authz_exception():
_session_db = {}
cons = Consumer(_session_db, client_config=CLIENT_CONFIG,
server_info=SERVER_INFO, **CONSUMER_CONFIG)
cons.debug = True
sid, loc = cons.begin("http://localhost:8087",
"http://localhost:8088/authorization")
atr = AuthorizationResponse(code="SplxlOBeZQQYbYS6WxSbIA",
state=sid)
adict = atr.to_dict()
del adict["code"]
QUERY_STRING = urllib.urlencode(adict)
raises(MissingRequiredAttribute,
"cons.handle_authorization_response(query=QUERY_STRING)")