def build_oauth_resource(request, format_type="json"):
    """
    Create a resource entry for oauth endpoint(s) for insertion
    into the conformance/capabilityStatement

    :return: security
    """
    endpoints = build_endpoint_info(OrderedDict(), issuer=base_issuer(request))
    print("\nEndpoints:%s" % endpoints)

    if format_type.lower() == "xml":

        security = """
<security>
    <extension url="http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris">
        <extension url="token">
            <valueUri>%s</valueUri>
        </extension>
        <extension url="authorize">
            <valueUri>%s</valueUri>
        </extension>
    </extension>

</security>
        """ % (endpoints['token_endpoint'],
               endpoints['authorization_endpoint'])

    else:  # json

        security = {}

        security['extension'] = [{
            "url":
            "http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris",
            "extension": [{
                "url": "token",
                "valueUri": endpoints['token_endpoint']
            }, {
                "url": "authorize",
                "valueUri": endpoints['authorization_endpoint']
            }]
        }]

    # print("\nSecurity Statement is:%s" % security)
    return security
Exemplo n.º 2
0
def build_oauth_resource(request, format_type="json"):
    """
    Create a resource entry for oauth endpoint(s) for insertion
    into the conformance/capabilityStatement

    :return: security
    """
    endpoints = build_endpoint_info(OrderedDict(), issuer=base_issuer(request))
    logger.info("\nEndpoints:%s" % endpoints)

    if format_type.lower() == "xml":

        security = """
<security>
    <cors>true</cors>
    <service>
        <text>OAuth</text>
        <coding>
            <system url="http://hl7.org/fhir/restful-security-service">
            <code>OAuth</code>
            <display>OAuth</display>
        </coding>
    </service>
    <service>
        <text>SMART-on-FHIR</text>
        <coding>
            <system url="http://hl7.org/fhir/restful-security-service">
            <code>SMART-on-FHIR</code>
            <display>SMART-on-FHIR</display>
        </coding>
    </service>
    <extension url="http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris">
        <extension url="token">
            <valueUri>%s</valueUri>
        </extension>
        <extension url="authorize">
            <valueUri>%s</valueUri>
        </extension>
    </extension>

</security>
        """ % (endpoints['token_endpoint'],
               endpoints['authorization_endpoint'])

    else:  # json

        security = {}

        security['cors'] = True
        security['service'] = [{
            "text":
            "OAuth",
            "coding": [{
                "system": "http://hl7.org/fhir/restful-security-service",
                "code": "OAuth",
                "display": "OAuth"
            }]
        }, {
            "text":
            "OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)",
            "coding": [{
                "system": "http://hl7.org/fhir/restful-security-service",
                "code": "SMART-on-FHIR",
                "display": "SMART-on-FHIR"
            }]
        }]
        security['extension'] = [{
            "url":
            "http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris",
            "extension": [{
                "url": "token",
                "valueUri": endpoints['token_endpoint']
            }, {
                "url": "authorize",
                "valueUri": endpoints['authorization_endpoint']
            }]
        }]

    return security