本文整理汇总了Python中oic.oic.message.OpenIDSchema类的典型用法代码示例。如果您正苦于以下问题:Python OpenIDSchema类的具体用法?Python OpenIDSchema怎么用?Python OpenIDSchema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OpenIDSchema类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_userinfo_endpoint
def test_userinfo_endpoint():
server = provider_init
_session_db = {}
cons = Consumer(_session_db, CONSUMER_CONFIG, CLIENT_CONFIG,
server_info=SERVER_INFO)
cons.debug = True
cons.client_secret = "drickyoughurt"
cons.config["response_type"] = ["token"]
cons.config["request_method"] = "parameter"
cons.keyjar[""] = KC_RSA
location = cons.begin("openid", "token", path="http://localhost:8087")
resp = server.authorization_endpoint(request=location.split("?")[1])
line = resp.message
path, query = line.split("?")
# redirect
atr = AuthorizationResponse().deserialize(query, "urlencoded")
uir = UserInfoRequest(access_token=atr["access_token"], schema="openid")
resp3 = server.userinfo_endpoint(request=uir.to_urlencoded())
ident = OpenIDSchema().deserialize(resp3.message, "json")
print ident.keys()
assert _eq(ident.keys(), ['nickname', 'sub', 'name', 'email'])
assert ident["sub"] == USERDB["username"]["sub"]
示例2: verify
def verify(self, **kwargs):
if "jwt" in self:
# Try to decode the JWT, checks the signature
try:
item = OpenIDSchema().from_jwt(str(self["jwt"]), kwargs["key"])
except Exception, _err:
raise Exception(_err.__class__.__name__)
if not item.verify(**kwargs):
return False
示例3: claims_info_endpoint
def claims_info_endpoint(self, environ, start_response, *args):
_log_info = logger.info
query = get_or_post(environ)
_log_info("Claims_info_endpoint query: '%s'" % query)
_log_info("environ: %s" % environ)
#ucreq = self.srvmethod.parse_userinfo_claims_request(query)
#_log_info("request: %s" % ucreq)
# Supposed to be "Bearer <access_token>
access_token = self._bearer_auth(environ)
uiresp = OpenIDSchema(**self.info_store[access_token])
resp = Response(uiresp.to_json(), content="application/json")
return resp(environ, start_response)
示例4: test_userinfo_endpoint_authn
def test_userinfo_endpoint_authn(self):
self.cons.client_secret = "drickyoughurt"
self.cons.config["response_type"] = ["token"]
self.cons.config["request_method"] = "parameter"
state, location = self.cons.begin("openid", "token", path="http://localhost:8087")
resp = self.provider.authorization_endpoint(request=urlparse(location).query)
# redirect
atr = AuthorizationResponse().deserialize(urlparse(resp.message).fragment, "urlencoded")
uir = UserInfoRequest(schema="openid")
resp = self.provider.userinfo_endpoint(request=uir.to_urlencoded(), authn="Bearer " + atr["access_token"])
ident = OpenIDSchema().deserialize(resp.message, "json")
assert _eq(ident.keys(), ["nickname", "sub", "name", "email"])
示例5: __call__
def __call__(self, request):
data = request.body
self.provider.parse_user_info_request(data)
_info = {
'sub': 'test-sub',
'name': 'Test User',
'nickname': 'Tester',
'email': '[email protected]',
'verified': True,
}
resp = OpenIDSchema(**_info)
userinfo = resp.to_json()
return (200, {'Content-Type': 'application/json'}, userinfo)
示例6: test_userinfo_endpoint
def test_userinfo_endpoint():
server = provider_init
_session_db = {}
cons = Consumer(_session_db, CONSUMER_CONFIG, CLIENT_CONFIG,
server_info=SERVER_INFO)
cons.debug = True
cons.client_secret = "drickyoughurt"
cons.config["response_type"] = ["token"]
cons.config["request_method"] = "parameter"
cons.keyjar[""] = KC_RSA
environ = BASE_ENVIRON
location = cons.begin(environ, start_response)
environ = BASE_ENVIRON.copy()
environ["QUERY_STRING"] = location.split("?")[1]
resp = server.authorization_endpoint(environ, start_response)
sid = resp[0][len("<form>"):-len("</form>")]
environ2 = create_return_form_env("user", "password", sid)
resp2 = server.authenticated(environ2, start_response)
line = resp2[0]
start = line.index("<title>")
start += len("<title>Redirecting to ")
stop = line.index("</title>")
path, query = line[start:stop].split("?")
# redirect
atr = AuthorizationResponse().deserialize(query, "urlencoded")
uir = UserInfoRequest(access_token=atr["access_token"], schema="openid")
environ = BASE_ENVIRON.copy()
environ["QUERY_STRING"] = uir.to_urlencoded()
resp3 = server.userinfo_endpoint(environ, start_response)
ident = OpenIDSchema().deserialize(resp3[0], "json")
print ident.keys()
assert _eq(ident.keys(), ['nickname', 'sub', 'name', 'email'])
assert ident["sub"] == USERDB["user"]["sub"]
示例7: test_userinfo_endpoint
def test_userinfo_endpoint(self):
self.cons.client_secret = "drickyoughurt"
self.cons.config["response_type"] = ["token"]
self.cons.config["request_method"] = "parameter"
state, location = self.cons.begin("openid", "token",
path="http://localhost:8087")
resp = self.server.authorization_endpoint(request=location.split("?")[1])
line = resp.message
path, query = line.split("#")
# redirect
atr = AuthorizationResponse().deserialize(query, "urlencoded")
uir = UserInfoRequest(access_token=atr["access_token"], schema="openid")
resp3 = self.server.userinfo_endpoint(request=uir.to_urlencoded())
ident = OpenIDSchema().deserialize(resp3.message, "json")
print ident.keys()
assert _eq(ident.keys(), ['nickname', 'sub', 'name', 'email'])
示例8: userinfo_endpoint
def userinfo_endpoint(self, request="", **kwargs):
"""
:param request: The request in a string format
"""
try:
_log_debug = kwargs["logger"].debug
_log_info = kwargs["logger"].info
except KeyError:
_log_debug = logger.debug
_log_info = logger.info
_sdb = self.sdb
if not request or "access_token" not in request:
_token = kwargs["authn"]
assert _token.startswith("Bearer ")
_token = _token[len("Bearer "):]
logger.debug("Bearer token: '%s'" % _token)
else:
uireq = self.server.parse_user_info_request(data=request)
logger.debug("user_info_request: %s" % uireq)
_token = uireq["access_token"]
# should be an access token
typ, key = _sdb.token.type_and_key(_token)
_log_debug("access_token type: '%s'" % (typ,))
try:
assert typ == "T"
except AssertionError:
raise FailedAuthentication("Wrong type of token")
#_log_info("keys: %s" % self.sdb.keys())
if _sdb.is_revoked(key):
return self._error(error="access_denied", descr="Token is revoked")
session = _sdb[key]
# Scope can translate to userinfo_claims
info = OpenIDSchema(**self._collect_user_info(session))
# Should I return a JSON or a JWT ?
_cinfo = self.cdb[session["client_id"]]
if "userinfo_signed_response_alg" in _cinfo:
algo = _cinfo["userinfo_signed_response_alg"]
# Use my key for signing
key = self.keyjar.get_signing_key(alg2keytype(algo), "")
jinfo = info.to_jwt(key, algo)
content_type = "application/jwt"
if "userinfo_encrypted_response_alg" in _cinfo:
# encrypt with clients public key
jinfo = self.encrypt(jinfo, _cinfo, session["client_id"],
"userinfo")
elif "userinfo_encrypted_response_alg" in _cinfo:
jinfo = self.encrypt(info.to_json(), _cinfo, session["client_id"],
"userinfo")
content_type = "application/jwt"
else:
jinfo = info.to_json()
content_type = "application/json"
return Response(jinfo, content=content_type)
示例9: make_userinfo_request
def make_userinfo_request(self, access_token):
resp = self.app.test_client().get('/userinfo', headers={'Authorization': 'Bearer {}'.format(access_token)})
assert resp.status_code == 200
userinfo = OpenIDSchema().from_json(resp.data.decode('utf-8'))
userinfo.verify()
return userinfo
示例10: trace_output
def trace_output(lines, index, end):
cont = False
seq = []
_cls = None
_data = []
_sent = {}
_recv = {}
phase = ""
while index < end:
line = lines[index]
if cont:
if line == "}":
_data.append(line)
cont = False
_args = json.loads("".join(_data))
if _cls == "JWKS":
try:
_inst = jwks_load("".join(_data))
except TypeError:
pass
elif _cls == "UserInfo":
_int = Message(**_args)
try:
_inst = OpenIDSchema(**_int["claims"])
except KeyError:
_inst = OpenIDSchema(**_args)
else:
try:
_inst.jwe_header = _int["jwe header parameters"]
except KeyError:
pass
try:
_inst.jws_header = _int["jws header parameters"]
except KeyError:
pass
else:
try:
_inst = oic_factory(_cls)(**_args)
except KeyError:
_inst = oauth2_factory(_cls)(**args)
seq.append((_cls, _inst))
else:
_data.append(line)
index += 1
continue
if line == DIV:
break
elif line == "Trace output" or line == "":
pass
else:
for phase in ORDER:
m = PATTERN[phase].match(line)
if m:
if phase == "head":
seq.append(m.groups()[0])
elif phase == "sent":
key, val = m.groups()
_sent[key] = val
elif phase == "recv":
key, val = m.groups()
_recv[key] = val
elif phase == "quer":
_recv["QUERY"] = m.groups()[0]
phase = "recv"
elif phase == "data":
m = DATA.match(line)
cont = True
_cls = m.groups()[0]
_data = ['{']
elif phase == "tag":
seq.append(("info", m.groups()[0]))
if phase in ["head", "data", "end"]:
if _sent:
seq.append(("sent", _sent))
_sent = {}
if _recv:
seq.append(("recv", _recv))
_recv = {}
break
if phase == "end":
break
index += 1
return index, seq
示例11: test_openidschema
def test_openidschema():
inp = '{"middle_name":null, "updated_at":"20170328081544", "sub":"abc"}'
ois = OpenIDSchema().from_json(inp)
assert ois.verify() is False