Skip to content

Commit

Permalink
adding smart on fhir configuration endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bwang-icf committed Nov 27, 2024
1 parent bc3004b commit c086578
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
5 changes: 5 additions & 0 deletions apps/wellknown/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from waffle.decorators import waffle_switch
from .views import (
openid_configuration,
smart_on_fhir_configuration,
ApplicationListView,
ApplicationLabelView,
PublicApplicationListView,
Expand All @@ -10,6 +11,7 @@

urlpatterns = [
path("openid-configuration", openid_configuration, name="openid-configuration"),
path("smart-on-fhir-configuration", smart_on_fhir_configuration, name="smart-on-fhir-configuration"),
path(
"applications",
waffle_switch("wellknown_applications")(ApplicationListView.as_view()),
Expand All @@ -28,6 +30,9 @@
path(
"openid-configuration-v2", openid_configuration, name="openid-configuration-v2"
),
path(
"smart-on-fhir-configuration", smart_on_fhir_configuration, name="smart-on-fhir-configuration"
),
path(
"applications-v2",
waffle_switch("wellknown_applications")(ApplicationListView.as_view()),
Expand Down
2 changes: 1 addition & 1 deletion apps/wellknown/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .openid import openid_configuration, base_issuer, build_endpoint_info # NOQA
from .openid import openid_configuration, smart_on_fhir_configuration, base_issuer, build_endpoint_info # NOQA
from .application import ApplicationListView, ApplicationLabelView # NOQA
from .public_applications import ApplicationListView as PublicApplicationListView # NOQA
39 changes: 38 additions & 1 deletion apps/wellknown/views/openid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@
import apps.logging.request_logger as bb2logging

logger = logging.getLogger(bb2logging.HHS_SERVER_LOGNAME_FMT.format(__name__))

SCOPES_SUPPORTED = ["profile", "patient/Patient.read", "patient/ExplanationOfBenefit.read", "patient/Coverage.read"]
CODE_CHALLENGE_METHODS_SUPPORTED = ["S256"]
CAPABILITIES = [
"client-confidential-symmetric",
"sso-openid-connect",
"launch-standalone",
"permission-offline",
"permission-patient",
"permission-v1"
]

@require_GET
def openid_configuration(request):
Expand All @@ -22,6 +31,17 @@ def openid_configuration(request):
data = build_endpoint_info(data, issuer=issuer, v2=v2)
return JsonResponse(data)

@require_GET
def smart_on_fhir_configuration(request):
"""
Views that returns smart_configuration.
"""
data = OrderedDict()
issuer = base_issuer(request)
v2 = request.path.endswith('smart-configuration-v2') or request.path.endswith('smartConfigV2')
data = build_smart_config_endpoint(data, issuer=issuer, v2=v2)
return JsonResponse(data)


def base_issuer(request):
"""
Expand Down Expand Up @@ -84,3 +104,20 @@ def build_endpoint_info(data=OrderedDict(), v2=False, issuer=""):
data["fhir_metadata_uri"] = issuer + \
reverse('fhir_conformance_metadata' if not v2 else 'fhir_conformance_metadata_v2')
return data

def build_smart_config_endpoint(data=OrderedDict(), v2=False, issuer=""):
"""
construct the smart config endpoint response. Takes in
issuer should be http: or https:// prefixed url.
:param data:
:return:
"""

data = build_endpoint_info(data, issuer=issuer, v2=v2)

data["scopes_supported"] = SCOPES_SUPPORTED
data["code_challenge_methods_supported"] = CODE_CHALLENGE_METHODS_SUPPORTED
data["capabilities"] = CAPABILITIES

return data

0 comments on commit c086578

Please sign in to comment.