本文整理汇总了Python中jwkest.jwk.KEYS类的典型用法代码示例。如果您正苦于以下问题:Python KEYS类的具体用法?Python KEYS怎么用?Python KEYS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KEYS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_loads_1
def test_loads_1():
jwk = {
"keys": [
{
"kty": "RSA",
"use": "foo",
"e": "AQAB",
"n": "wf-wiusGhA-gleZYQAOPQlNUIucPiqXdPVyieDqQbXXOPBe3nuggtVzeq7pVFH1dZz4dY2Q2LA5DaegvP8kRvoSB_87ds3dy3Rfym_GUSc5B0l1TgEobcyaep8jguRoHto6GWHfCfKqoUYZq4N8vh4LLMQwLR6zi6Jtu82nB5k8",
"kid": "1",
},
{
"kty": "RSA",
"use": "bar",
"e": "AQAB",
"n": "wf-wiusGhA-gleZYQAOPQlNUIucPiqXdPVyieDqQbXXOPBe3nuggtVzeq7pVFH1dZz4dY2Q2LA5DaegvP8kRvoSB_87ds3dy3Rfym_GUSc5B0l1TgEobcyaep8jguRoHto6GWHfCfKqoUYZq4N8vh4LLMQwLR6zi6Jtu82nB5k8",
"kid": "2",
},
]
}
keys = KEYS()
keys.load_dict(jwk)
print(keys)
assert len(keys) == 2
assert _eq(keys.kids(), ["1", "2"])
示例2: get_jwks_keys
def get_jwks_keys(self):
keys = KEYS()
keys.load_from_url(self.jwks_uri())
# Add client secret as oct key so it can be used for HMAC signatures
client_id, client_secret = self.get_key_and_secret()
keys.add({'key': client_secret, 'kty': 'oct'})
return keys
示例3: signing_keys
def signing_keys(self):
if self.signing_alg == self.RS256:
# TODO perform caching, OBVIOUS
key = KEYS()
key.load_from_url(self.jwks_uri)
rsa_key = key.as_dict()['RSA']
return rsa_key
return [SYMKey(key=str(self.client_secret))]
示例4: _get_keys
def _get_keys(self):
"""
Get public key from discovery.
"""
request = self.factory.get(reverse('oidc_provider:jwks'))
response = JwksView.as_view()(request)
jwks_dic = json.loads(response.content.decode('utf-8'))
SIGKEYS = KEYS()
SIGKEYS.load_dict(jwks_dic)
return SIGKEYS
示例5: test_dump_jwk
def test_dump_jwk():
keylist0 = KEYS()
keylist0.wrap_add(pem_cert2rsa(CERT))
jwk = keylist0.dump_jwks()
print(jwk)
_wk = json.loads(jwk)
assert list(_wk.keys()) == ["keys"]
assert len(_wk["keys"]) == 1
assert _eq(list(_wk["keys"][0].keys()), ["kty", "e", "n"])
示例6: setUp
def setUp(self):
self.user = User.objects.create(username='henk')
mock_get = self.patch('requests.get')
mock_get.return_value.json.return_value = {"jwks_uri": "http://example.com/jwks",
"issuer": "http://example.com"}
keys = KEYS()
keys.add({'key': key, 'kty': 'RSA'})
self.patch('jwkest.jwk.request', return_value=Mock(status_code=200,
text=keys.dump_jwks()))
api_settings.OIDC_ENDPOINT = 'http://example.com'
api_settings.OIDC_AUDIENCE = 'you'
示例7: test_loads_0
def test_loads_0():
keys = KEYS()
keys.load_dict(JWK)
assert len(keys) == 1
key = keys["rsa"][0]
assert key.kid == 'abc'
assert key.kty == 'RSA'
_ckey = pem_cert2rsa(CERT)
print(key)
assert key.n == _ckey.n
assert key.e == _ckey.e
示例8: setUp
def setUp(self):
self.user = User.objects.create(username='henk')
self.responder = FakeRequests()
self.responder.set_response("http://example.com/.well-known/openid-configuration",
{"jwks_uri": "http://example.com/jwks",
"issuer": "http://example.com",
"userinfo_endpoint": "http://example.com/userinfo"})
self.mock_get = self.patch('requests.get')
self.mock_get.side_effect = self.responder.get
keys = KEYS()
keys.add({'key': key, 'kty': 'RSA', 'kid': key.kid})
self.patch('jwkest.jwk.request', return_value=Mock(status_code=200,
text=keys.dump_jwks()))
示例9: get_jwks_keys
def get_jwks_keys(self):
"""
Returns the keys used by the IdP.
Merges client secret into JWK set from server
Response is cached for 24 hours.
"""
keys = KEYS()
keys.load_from_url(self.JWKS_URI)
# Add client secret as oct key so it can be used for HMAC signatures
_client_id, client_secret = self.get_key_and_secret()
keys.add({'key': client_secret, 'kty': 'oct'})
return keys
示例10: test_sign_2
def test_sign_2():
keyset = {"keys": [
{"alg": "RS512",
"kty": "RSA",
"d": "ckLyXxkbjC4szg8q8G0ERBZV-9CszeOxpRtx1KM9BLl0Do3li_Km2vvFvfXJ7MxQpiZ18pBoCcyYQEU262ym8wI22JWMPrZe24HCNxLxqzr_JEuBhpKFxQF6EFTSvJEJD1FkoTuCTvN0zD7YHGaJQG6JzVEuFUY3ewxjH0FYNa_ppTnPP3LC-T9u_GX9Yqyuw1KOYoHSzhWSWQOeAgs4dH9-iAxN1wdZ6eH1jFWAs43svk_rhwdgyJMlihFtV9MAInBlfi_Zu8wRVhVl5urkJrLf0tGFnMbnzb6dYSlUXxEYClpY12W7kXW9aePDqkCwI4oZyxmOmgq4hunKGR1dAQ",
"e": "AQAB",
"use": "sig",
"kid": "af22448d-4c7b-464d-b63a-f5bd90f6d7d1",
"n": "o9g8DpUwBW6B1qmcm-TfEh4rNX7n1t38jdo4Gkl_cI3q--7n0Blg0kN88LHZvyZjUB2NhBdFYNxMP8ucy0dOXvWGWzaPmGnq3DM__lN8P4WjD1cCTAVEYKawNBAmGKqrFj1SgpPNsSqiqK-ALM1w6mZ-QGimjOgwCyJy3l9lzZh5D8tKnS2t1pZgE0X5P7lZQWHYpHPqp4jKhETzrCpPGfv0Rl6nmmjp7NlRYBkWKf_HEKE333J6M039m2FbKgxrBg3zmYYpmHuMzVgxxb8LSiv5aqyeyJjxM-YDUAgNQBfKNhONqXyu9DqtSprNkw6sqmuxK0QUVrNYl3b03PgS5Q"
}]}
keys = KEYS()
keys.load_dict(keyset)
jws = JWS("payload", alg="RS512")
jws.sign_compact(keys=keys)
示例11: _get_keys
def _get_keys(self):
if "jwk" in self:
return [self["jwk"]]
elif "jku" in self:
keys = KEYS()
keys.load_from_url(self["jku"])
return keys.as_dict()
elif "x5u" in self:
try:
return {"rsa": [load_x509_cert(self["x5u"], {})]}
except Exception:
# ca_chain = load_x509_cert_chain(self["x5u"])
pass
return {}
示例12: encode
def encode(self, payload):
"""Encode the provided payload."""
keys = KEYS()
if self.asymmetric:
keys.add(RSAKey(key=RSA.importKey(settings.JWT_PRIVATE_SIGNING_KEY)))
algorithm = 'RS512'
else:
key = self.secret if self.secret else self.jwt_auth['JWT_SECRET_KEY']
keys.add({'key': key, 'kty': 'oct'})
algorithm = self.jwt_auth['JWT_ALGORITHM']
data = json.dumps(payload)
jws = JWS(data, alg=algorithm)
return jws.sign_compact(keys=keys)
示例13: _get_signing_jwk_key_set
def _get_signing_jwk_key_set(jwt_issuer):
"""
Returns a JWK Keyset containing all active keys that are configured
for verifying signatures.
"""
key_set = KEYS()
# asymmetric keys
signing_jwk_set = settings.JWT_AUTH.get('JWT_PUBLIC_SIGNING_JWK_SET')
if signing_jwk_set:
key_set.load_jwks(signing_jwk_set)
# symmetric key
key_set.add({'key': jwt_issuer['SECRET_KEY'], 'kty': 'oct'})
return key_set
示例14: _get_keys
def _get_keys(self):
logger.debug("_get_keys(): self._dict.keys={0}".format(
self._dict.keys()))
if "jwk" in self:
return [self["jwk"]]
elif "jku" in self:
keys = KEYS()
keys.load_from_url(self["jku"])
return keys.as_dict()
elif "x5u" in self:
try:
return {"rsa": [load_x509_cert(self["x5u"], {})]}
except Exception:
# ca_chain = load_x509_cert_chain(self["x5u"])
pass
return {}
示例15: _decode_jwt
def _decode_jwt(verify_expiration):
"""
Helper method to decode a JWT with the ability to
verify the expiration of said token
"""
keys = KEYS()
if should_be_asymmetric_key:
keys.load_jwks(settings.JWT_AUTH['JWT_PUBLIC_SIGNING_JWK_SET'])
else:
keys.add({'key': secret_key, 'kty': 'oct'})
_ = JWS().verify_compact(access_token.encode('utf-8'), keys)
return jwt.decode(
access_token,
secret_key,
algorithms=[settings.JWT_AUTH['JWT_ALGORITHM']],
audience=audience,
issuer=issuer,
verify_expiration=verify_expiration,
options={'verify_signature': False},
)