Skip to content

Commit e6e6518

Browse files
authored
Merge pull request #203673 from rwallerms/users/rwaller/UpdateAADPassword
Update IR Create script to auto-create AAD app password due to recent…
2 parents 6be0a38 + 26158fd commit e6e6518

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

articles/applied-ai-services/immersive-reader/how-to-create-immersive-reader.md

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ manager: nitinme
99
ms.service: applied-ai-services
1010
ms.subservice: immersive-reader
1111
ms.topic: how-to
12-
ms.date: 11/11/2021
12+
ms.date: 7/1/2022
1313
ms.author: rwaller
1414
---
1515

@@ -38,9 +38,8 @@ The script is designed to be flexible. It will first look for existing Immersive
3838
[Parameter(Mandatory=$true)] [String] $ResourceLocation,
3939
[Parameter(Mandatory=$true)] [String] $ResourceGroupName,
4040
[Parameter(Mandatory=$true)] [String] $ResourceGroupLocation,
41-
[Parameter(Mandatory=$true)] [String] $AADAppDisplayName="ImmersiveReaderAAD",
41+
[Parameter(Mandatory=$true)] [String] $AADAppDisplayName,
4242
[Parameter(Mandatory=$true)] [String] $AADAppIdentifierUri,
43-
[Parameter(Mandatory=$true)] [String] $AADAppClientSecret,
4443
[Parameter(Mandatory=$true)] [String] $AADAppClientSecretExpiration
4544
)
4645
{
@@ -90,31 +89,37 @@ The script is designed to be flexible. It will first look for existing Immersive
9089
$clientId = az ad app show --id $AADAppIdentifierUri --query "appId" -o tsv
9190
if (-not $clientId) {
9291
Write-Host "Creating new Azure Active Directory app"
93-
$clientId = az ad app create --password $AADAppClientSecret --end-date "$AADAppClientSecretExpiration" --display-name $AADAppDisplayName --identifier-uris $AADAppIdentifierUri --query "appId" -o tsv
94-
92+
$clientId = az ad app create --display-name $AADAppDisplayName --identifier-uris $AADAppIdentifierUri --query "appId" -o tsv
9593
if (-not $clientId) {
96-
throw "Error: Failed to create Azure Active Directory app"
94+
throw "Error: Failed to create Azure Active Directory application"
95+
}
96+
Write-Host "Azure Active Directory application created successfully."
97+
98+
$clientSecret = az ad app credential reset --id $clientId --end-date "$AADAppClientSecretExpiration" --query "password" | % { $_.Trim('"') }
99+
if (-not $clientSecret) {
100+
throw "Error: Failed to create Azure Active Directory application client secret"
97101
}
98-
Write-Host "Azure Active Directory app created successfully."
99-
Write-Host "NOTE: To manage your Active Directory app client secrets after this Immersive Reader Resource has been created please visit https://portal.azure.com and go to Home -> Azure Active Directory -> App Registrations -> $AADAppDisplayName -> Certificates and Secrets blade -> Client Secrets section" -ForegroundColor Yellow
102+
Write-Host "Azure Active Directory application client secret created successfully."
103+
104+
Write-Host "NOTE: To manage your Active Directory application client secrets after this Immersive Reader Resource has been created please visit https://portal.azure.com and go to Home -> Azure Active Directory -> App Registrations -> (your app) '$AADAppDisplayName' -> Certificates and Secrets blade -> Client Secrets section" -ForegroundColor Yellow
100105
}
101106
102107
# Create a service principal if it doesn't already exist
103-
$principalId = az ad sp show --id $AADAppIdentifierUri --query "objectId" -o tsv
108+
$principalId = az ad sp show --id $AADAppIdentifierUri --query "id" -o tsv
104109
if (-not $principalId) {
105110
Write-Host "Creating new service principal"
106111
az ad sp create --id $clientId | Out-Null
107-
$principalId = az ad sp show --id $AADAppIdentifierUri --query "objectId" -o tsv
112+
$principalId = az ad sp show --id $AADAppIdentifierUri --query "id" -o tsv
108113
109114
if (-not $principalId) {
110115
throw "Error: Failed to create new service principal"
111116
}
112117
Write-Host "New service principal created successfully"
113-
}
114118
115-
# Sleep for 5 seconds to allow the new service principal to propagate
116-
Write-Host "Sleeping for 5 seconds"
117-
Start-Sleep -Seconds 5
119+
# Sleep for 5 seconds to allow the new service principal to propagate
120+
Write-Host "Sleeping for 5 seconds"
121+
Start-Sleep -Seconds 5
122+
}
118123
119124
Write-Host "Granting service principal access to the newly created Immersive Reader resource"
120125
$accessResult = az role assignment create --assignee $principalId --scope $resourceId --role "Cognitive Services Immersive Reader User"
@@ -130,22 +135,32 @@ The script is designed to be flexible. It will first look for existing Immersive
130135
$result = @{}
131136
$result.TenantId = $tenantId
132137
$result.ClientId = $clientId
133-
$result.ClientSecret = $AADAppClientSecret
138+
$result.ClientSecret = $clientSecret
134139
$result.Subdomain = $ResourceSubdomain
135140
136-
Write-Host "Success! " -ForegroundColor Green -NoNewline
137-
Write-Host "Save the following JSON object to a text file for future reference:"
141+
Write-Host "`nSuccess! " -ForegroundColor Green -NoNewline
142+
Write-Host "Save the following JSON object to a text file for future reference."
143+
Write-Host "*****"
144+
if($clientSecret -ne $null) {
145+
146+
Write-Host "This function has created a client secret (password) for you. This secret is used when calling Azure Active Directory to fetch access tokens."
147+
Write-Host "This is the only time you will ever see the client secret for your Azure Active Directory application, so save it now." -ForegroundColor Yellow
148+
}
149+
else{
150+
Write-Host "You will need to retrieve the ClientSecret from your original run of this function that created it. If you don't have it, you will need to go create a new client secret for your Azure Active Directory application. Please visit https://portal.azure.com and go to Home -> Azure Active Directory -> App Registrations -> (your app) '$AADAppDisplayName' -> Certificates and Secrets blade -> Client Secrets section." -ForegroundColor Yellow
151+
}
152+
Write-Host "*****`n"
138153
Write-Output (ConvertTo-Json $result)
139154
}
140155
```
141156
142157
1. Run the function `Create-ImmersiveReaderResource`, supplying the '<PARAMETER_VALUES>' placeholders below with your own values as appropriate.
143158
144159
```azurepowershell-interactive
145-
Create-ImmersiveReaderResource -SubscriptionName '<SUBSCRIPTION_NAME>' -ResourceName '<RESOURCE_NAME>' -ResourceSubdomain '<RESOURCE_SUBDOMAIN>' -ResourceSKU '<RESOURCE_SKU>' -ResourceLocation '<RESOURCE_LOCATION>' -ResourceGroupName '<RESOURCE_GROUP_NAME>' -ResourceGroupLocation '<RESOURCE_GROUP_LOCATION>' -AADAppDisplayName '<AAD_APP_DISPLAY_NAME>' -AADAppIdentifierUri '<AAD_APP_IDENTIFIER_URI>' -AADAppClientSecret '<AAD_APP_CLIENT_SECRET>' -AADAppClientSecretExpiration '<AAD_APP_CLIENT_SECRET_EXPIRATION>'
160+
Create-ImmersiveReaderResource -SubscriptionName '<SUBSCRIPTION_NAME>' -ResourceName '<RESOURCE_NAME>' -ResourceSubdomain '<RESOURCE_SUBDOMAIN>' -ResourceSKU '<RESOURCE_SKU>' -ResourceLocation '<RESOURCE_LOCATION>' -ResourceGroupName '<RESOURCE_GROUP_NAME>' -ResourceGroupLocation '<RESOURCE_GROUP_LOCATION>' -AADAppDisplayName '<AAD_APP_DISPLAY_NAME>' -AADAppIdentifierUri '<AAD_APP_IDENTIFIER_URI>' -AADAppClientSecretExpiration '<AAD_APP_CLIENT_SECRET_EXPIRATION>'
146161
```
147162
148-
The full command will look something like the following. Here we have put each parameter on its own line for clarity, so you can see the whole command. Do not copy or use this command as-is. Copy and use the command above with your own values. This example has dummy values for the '<PARAMETER_VALUES>' above. Yours will be different, as you will come up with your own names for these values.
163+
The full command will look something like the following. Here we have put each parameter on its own line for clarity, so you can see the whole command. __Do not copy or use this command as-is.__ Copy and use the command above with your own values. This example has dummy values for the '<PARAMETER_VALUES>' above. Yours will be different, as you will come up with your own names for these values.
149164
150165
```
151166
Create-ImmersiveReaderResource
@@ -158,7 +173,6 @@ The script is designed to be flexible. It will first look for existing Immersive
158173
-ResourceGroupLocation 'westus2'
159174
-AADAppDisplayName 'MyOrganizationImmersiveReaderAADApp'
160175
-AADAppIdentifierUri 'api://MyOrganizationImmersiveReaderAADApp'
161-
-AADAppClientSecret 'SomeStrongPassword'
162176
-AADAppClientSecretExpiration '2021-12-31'
163177
```
164178
@@ -168,13 +182,12 @@ The script is designed to be flexible. It will first look for existing Immersive
168182
| ResourceName | Must be alphanumeric, and may contain '-', as long as the '-' is not the first or last character. Length may not exceed 63 characters.|
169183
| ResourceSubdomain |A custom subdomain is needed for your Immersive Reader resource. The subdomain is used by the SDK when calling the Immersive Reader service to launch the Reader. The subdomain must be globally unique. The subdomain must be alphanumeric, and may contain '-', as long as the '-' is not the first or last character. Length may not exceed 63 characters. This parameter is optional if the resource already exists. |
170184
| ResourceSKU |Options: `S0` (Standard tier) or `S1` (Education/Nonprofit organizations). Visit our [Cognitive Services pricing page](https://azure.microsoft.com/pricing/details/cognitive-services/immersive-reader/) to learn more about each available SKU. This parameter is optional if the resource already exists. |
171-
| ResourceLocation |Options: `eastus`, `eastus2`, `southcentralus`, `westus`, `westus2`, `australiaeast`, `southeastasia`, `centralindia`, `japaneast`, `northeurope`, `uksouth`, `westeurope`. This parameter is optional if the resource already exists. |
185+
| ResourceLocation |Options: `australiaeast`, `brazilsouth`, `canadacentral`, `centralindia`, `centralus`, `eastasia`, `eastus`, `eastus2`, `francecentral`, `germanywestcentral`, `japaneast`, `japanwest`, `jioindiawest`, `koreacentral`, `northcentralus`, `northeurope`, `norwayeast`, `southafricanorth`, `southcentralus`, `southeastasia`, `swedencentral`, `switzerlandnorth`, `switzerlandwest`, `uaenorth`, `uksouth`, `westcentralus`, `westeurope`, `westus`, `westus2`, `westus3`. This parameter is optional if the resource already exists. |
172186
| ResourceGroupName |Resources are created in resource groups within subscriptions. Supply the name of an existing resource group. If the resource group does not already exist, a new one with this name will be created. |
173187
| ResourceGroupLocation |If your resource group doesn't exist, you need to supply a location in which to create the group. To find a list of locations, run `az account list-locations`. Use the *name* property (without spaces) of the returned result. This parameter is optional if your resource group already exists. |
174188
| AADAppDisplayName |The Azure Active Directory application display name. If an existing Azure AD application is not found, a new one with this name will be created. This parameter is optional if the Azure AD application already exists. |
175-
| AADAppIdentifierUri |The URI for the Azure AD app. If an existing Azure AD app is not found, a new one with this URI will be created. For example, `api://MyOrganizationImmersiveReaderAADApp`. Here we are using the default Azure AD URI scheme prefix of `api://` for compatibility with the [Azure AD policy of using verified domains](../../active-directory/develop/reference-breaking-changes.md#appid-uri-in-single-tenant-applications-will-require-use-of-default-scheme-or-verified-domains). |
176-
| AADAppClientSecret |A password you create that will be used later to authenticate when acquiring a token to launch the Immersive Reader. The password must be at least 16 characters long, contain at least 1 special character, and contain at least 1 numeric character. To manage Azure AD application client secrets after you've created this resource please visit https://portal.azure.com and go to Home -> Azure Active Directory -> App Registrations -> `[AADAppDisplayName]` -> Certificates and Secrets blade -> Client Secrets section (as shown in the "Manage your Azure AD application secrets" screenshot below). |
177-
| AADAppClientSecretExpiration |The date or datetime after which your `[AADAppClientSecret]` will expire (e.g. '2020-12-31T11:59:59+00:00' or '2020-12-31'). |
189+
| AADAppIdentifierUri |The URI for the Azure AD application. If an existing Azure AD application is not found, a new one with this URI will be created. For example, `api://MyOrganizationImmersiveReaderAADApp`. Here we are using the default Azure AD URI scheme prefix of `api://` for compatibility with the [Azure AD policy of using verified domains](../../active-directory/develop/reference-breaking-changes.md#appid-uri-in-single-tenant-applications-will-require-use-of-default-scheme-or-verified-domains). |
190+
| AADAppClientSecretExpiration |The date or datetime after which your AAD Application Client Secret (password) will expire (e.g. '2020-12-31T11:59:59+00:00' or '2020-12-31'). This function will create a client secret for you. To manage Azure AD application client secrets after you've created this resource, please visit https://portal.azure.com and go to Home -> Azure Active Directory -> App Registrations -> (your app) `[AADAppDisplayName]` -> Certificates and Secrets blade -> Client Secrets section (as shown in the "Manage your Azure AD application secrets" screenshot below).|
178191
179192
Manage your Azure AD application secrets
180193

0 commit comments

Comments
 (0)