mirror of
https://github.com/suitenumerique/docs.git
synced 2026-09-26 19:45:01 +02:00
✨(backend) publish the JWT public key on a JWKS endpoint
The yhub service will need our public key in order to validate the jwt token we will used. We choose to expose a jwks endpoint as it is a standard wat to do this.
This commit is contained in:
@@ -64,6 +64,10 @@ from core.services.converter_services import (
|
||||
from core.services.converter_services import (
|
||||
ValidationError as YProviderValidationError,
|
||||
)
|
||||
from core.services.jwt_services import (
|
||||
ConfigurationError as JWTConfigurationError,
|
||||
)
|
||||
from core.services.jwt_services import JWTService
|
||||
from core.services.search_indexers import (
|
||||
get_document_indexer,
|
||||
get_visited_document_ids_of,
|
||||
@@ -3183,6 +3187,26 @@ class ConfigView(drf.views.APIView):
|
||||
return theme_customization
|
||||
|
||||
|
||||
class JWKSView(drf.views.APIView):
|
||||
"""API ViewSet exposing the public key validating the tokens we issue."""
|
||||
|
||||
authentication_classes = []
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def get(self, request):
|
||||
"""
|
||||
GET /api/v1.0/jwks
|
||||
Return the JSON Web Key Set of the tokens issued by this service.
|
||||
"""
|
||||
try:
|
||||
jwks = JWTService().get_jwks()
|
||||
except JWTConfigurationError:
|
||||
logger.exception("Unable to publish the JWKS")
|
||||
raise drf.exceptions.NotFound("No JWKS available.") from None
|
||||
|
||||
return drf.response.Response(jwks)
|
||||
|
||||
|
||||
class CommentViewSetMixin:
|
||||
"""Comment ViewSet Mixin."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user