def claims_ser(val, sformat="urlencoded", lev=0): # everything in c_extension if isinstance(val, str): item = val elif isinstance(val, list): item = val[0] else: item = val if isinstance(item, Message): return item.serialize(method=sformat, lev=lev + 1) if sformat == "urlencoded": res = urlencode(item) elif sformat == "json": if lev: res = item else: res = json.dumps(item) elif sformat == "dict": if isinstance(item, dict): res = item else: raise MessageException("Wrong type: %s" % type(item)) else: raise OidcMsgError("Unknown sformat: %s" % sformat, val) return res
def authorization(self, request, **kwargs): areq = AuthorizationRequest().from_urlencoded(request) if not areq.verify(): raise OidcMsgError('Verification failed') resp = HTTPResponse('OK') return resp
def link_ser(inst, sformat, lev=0): if sformat in ["urlencoded", "json"]: if isinstance(inst, dict): if sformat == "json": res = json.dumps(inst) else: res = urlencode([(k, v) for k, v in inst.items()]) elif isinstance(inst, Link): res = inst.serialize(sformat, lev) else: res = inst elif sformat == "dict": if isinstance(inst, Link): res = inst.serialize(sformat, lev) elif isinstance(inst, dict): res = inst elif isinstance(inst, str): # Iff ID Token res = inst else: raise MessageException("Wrong type: %s" % type(inst)) else: raise OidcMsgError("Unknown sformat", inst) return res