This repository has been archived by the owner on Sep 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathPrepareFhirDemo.ps1
51 lines (42 loc) · 2.11 KB
/
PrepareFhirDemo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
param(
[Parameter(Mandatory = $true )]
[ValidateLength(1,12)]
[string]$EnvironmentName
)
if (-not (Get-Module -Name "FhirServer"))
{
throw "Please load module FhirServer"
}
# Get current AzureAd context
try {
Get-AzureADCurrentSessionInfo -ErrorAction Stop | Out-Null
}
catch {
throw "Please log in to Azure AD with Connect-AzureAD cmdlet before proceeding"
}
$username = (Get-AzureADCurrentSessionInfo).Account.Id
$username_rep = $username.Replace('@','_') #External accounts have a different form of UPN
$aadUser = Get-AzureADUser -Filter "startswith(userPrincipalName, '$username') or startswith(userPrincipalName, '$username_rep')"
$fhirServiceName = $environmentName + "srvr"
$fhirClientName = $environmentName + "client"
$fhirServiceClientName = $environmentName + "service"
$fhirServerUrl = "https://" + $fhirServiceName + ".azurewebsites.net"
$fhirClientUrl = "https://" + $fhirClientName + ".azurewebsites.net"
$fhirClientReplyUrl = $fhirClientUrl + "/.auth/login/aad/callback"
$apiAppReg = New-FhirServerApiApplicationRegistration -FhirServiceName $fhirServiceName -AppRoles admin
$clientAppReg = New-FhirServerClientApplicationRegistration -ApiAppId $apiAppReg.AppId -DisplayName $fhirClientName -IdentifierUri $fhirClientUrl -ReplyUrl $fhirClientReplyUrl
$serviceClientAppReg = New-FhirServerClientApplicationRegistration -ApiAppId $apiAppReg.AppId -DisplayName $fhirServiceClientName
# Make the app registration an admin, since we will be using it for data movement
# This could be a separate service principal
Set-FhirServerClientAppRoleAssignments -AppId $serviceClientAppReg.AppId -ApiAppId $apiAppReg.AppId -AppRoles admin
# Make the current user an admin
Set-FhirServerUserAppRoleAssignments -UserPrincipalName $aadUser.UserPrincipalName -ApiAppId $apiAppReg.AppId -AppRoles admin
@{
environmentName = $EnvironmentName;
aadAuthority = $apiAppReg.Authority;
aadClientId = $clientAppReg.AppId;
aadClientSecret = $clientAppReg.AppSecret;
aadAudience = $apiAppReg.Audience;
aadServiceClientId = $serviceClientAppReg.AppId;
aadServiceClientSecret = $serviceClientAppReg.AppSecret
}