Skip to content

Instantly share code, notes, and snippets.

@hansenms
Last active May 27, 2020 17:50
Show Gist options
  • Save hansenms/63775aaab5e1d310d20401c36dc15bb5 to your computer and use it in GitHub Desktop.
Save hansenms/63775aaab5e1d310d20401c36dc15bb5 to your computer and use it in GitHub Desktop.

Azure API for FHIR with Service Principal Access

Pre-requisites

  1. Make sure you have the latest version of the Az PowerShell module (>= 4.1)

Provision API and Service Principal

First create a resource group if you do not have one:

New-AzResourceGroup -Location <location> -Name <resource group name>

Create FHIR API:

$fhirApi = Get-AzHealthcareApisService -name <fhir service name> -ResourceGroupName <resource group name>

Then create service principal with data plane privileges:

$sp = New-AzADServicePrincipal -DisplayName "mihansen-fhir-api-sp" -Role "FHIR Data Contributor" -Scope $fhirApi.Id

And to get all the details:

$details = @{
  clientId = $sp.Id
  clientSecret = $(New-Object PSCredential "user",$sp.secret).GetNetworkCredential().Password
  fhirServerUrl = "https://" + $fhirApi.Name + ".azurehealthcareapis.com"
  tokenUrl = $fhirApi.Audience + "/oauth2/v2.0/token"
  scope = $fhirApi.Audience + "/user_impersonation"
}

# Print the details
$details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment