def _create_jwt(self, claim: Dict[str, Any], key_pemstr: str) -> str:
_log.debug("Encoding JWT response: %s", claim)
fp = base64.b32encode(
SHA256.new(
data=RSA.importKey(key_pemstr).publickey().exportKey(format="DER")
).digest()[0:30] # shorten to 240 bit presumably so no padding is necessary
).decode('utf-8')
kid = ":".join([fp[i:i + 4] for i in range(0, len(fp), 4)])
jwtstr = jwt.encode(
claim,
headers={
"typ": "JWT",
"alg": "RS256",
"kid": kid,
},
key=key_pemstr,
algorithm="RS256",
).decode('utf-8')
_log.debug("JWT response: %s", jwtstr)
return jwtstr
评论列表
文章目录