Authenticate to FHIR API without manually requesting an access token

Domien Van Steendam 45 Reputation points
2023-06-28T16:41:17.42+00:00

My app is hosted on Azure and has a corresponding service principal enabled. Currently my app gets 401 whenever it sends requests to FHIR API, simply because I didn't add any authentication in my app.

How can I easily integrate Azure AD with my app so that it can make succesfull requests to FHIR API?

I do not want to deal with client secret properties in my app. I simply want to identify my app with new DefaultAzureCredential() and request tokens from there.

For example, I wish to simply use DefaultAzureCredential.GetToken(), this would not require any code changes despite the app running locally or in production environment.

Another example which would be ideal (for storage instead of FHIR)

new BlobServiceClient(
        new Uri($"https://{accountName}.blob.core.windows.net"),
        new DefaultAzureCredential());
Azure Health Data Services
Azure Health Data Services
An Azure offering that provides a suite of purpose-built technologies for protected health information in the cloud.
150 questions
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,151 Reputation points
    2023-06-29T15:33:02.3166667+00:00

    Domien Van Steendam Thanks for sharing the additional details. Since you already know how to use DefaultAzureCredential in Azure App Service (DefaultAzureCredential.GetToken() to retrieve the access token), I will focus on Firely SDK part of the question.

    Looking at the code snippet, it appears Authorization header was not added to FhirClient class and hence error 401 Unauthenticated was thrown. Check out Message Handlers doc and you would need to add a custom handler to FhirClient which should add Authorization before making the request. The doc has a code snippet to specifically add Authorization header and you can also add additional headers if needed.

    If you have any more questions about the usage of firely-net-sdk, I suggest you posting it in repo: Issues and for Discussions. I hope this helps and let me know if you have any questions.


    If you found the answer to your question helpful, please take a moment to mark it as "Yes" for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful