providers/oauth2: fix invalid assignments in JWKS view

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-12-22 22:41:28 +01:00
parent f458cae954
commit 0149c89003
1 changed files with 7 additions and 4 deletions

View File

@ -11,6 +11,7 @@ from django.shortcuts import get_object_or_404
from django.views import View from django.views import View
from authentik.core.models import Application from authentik.core.models import Application
from authentik.crypto.models import CertificateKeyPair
from authentik.providers.oauth2.models import JWTAlgorithms, OAuth2Provider from authentik.providers.oauth2.models import JWTAlgorithms, OAuth2Provider
@ -29,11 +30,13 @@ class JWKSView(View):
"""Show RSA Key data for Provider""" """Show RSA Key data for Provider"""
application = get_object_or_404(Application, slug=application_slug) application = get_object_or_404(Application, slug=application_slug)
provider: OAuth2Provider = get_object_or_404(OAuth2Provider, pk=application.provider_id) provider: OAuth2Provider = get_object_or_404(OAuth2Provider, pk=application.provider_id)
private_key = provider.signing_key signing_key: CertificateKeyPair = provider.signing_key
response_data = {} response_data = {}
if private_key: if signing_key:
private_key = signing_key.private_key
print(type(private_key))
if isinstance(private_key, RSAPrivateKey): if isinstance(private_key, RSAPrivateKey):
public_key: RSAPublicKey = private_key.public_key() public_key: RSAPublicKey = private_key.public_key()
public_numbers = public_key.public_numbers() public_numbers = public_key.public_numbers()
@ -42,7 +45,7 @@ class JWKSView(View):
"kty": "RSA", "kty": "RSA",
"alg": JWTAlgorithms.RS256, "alg": JWTAlgorithms.RS256,
"use": "sig", "use": "sig",
"kid": private_key.kid, "kid": signing_key.kid,
"n": b64_enc(public_numbers.n), "n": b64_enc(public_numbers.n),
"e": b64_enc(public_numbers.e), "e": b64_enc(public_numbers.e),
} }
@ -55,7 +58,7 @@ class JWKSView(View):
"kty": "EC", "kty": "EC",
"alg": JWTAlgorithms.EC256, "alg": JWTAlgorithms.EC256,
"use": "sig", "use": "sig",
"kid": private_key.kid, "kid": signing_key.kid,
"n": b64_enc(public_numbers.n), "n": b64_enc(public_numbers.n),
"e": b64_enc(public_numbers.e), "e": b64_enc(public_numbers.e),
} }