Skip to content

Commit befbc13

Browse files
authored
Merge pull request #149 from Azure-Samples/shama-k/Master+MIW2.0+ReadMePoP
Implementation and Readme Changes
2 parents 63087e8 + 0e5450b commit befbc13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1000
-3036
lines changed

1. Desktop app calls Web API/AppCreationScripts/AppCreationScripts.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Registering the sample apps with Microsoft Identity Platform and updating the configuration files using PowerShell scripts
1+
# Registering the sample apps with Microsoft identity platform and updating the configuration files using PowerShell scripts
22

33
## Overview
44

@@ -11,7 +11,8 @@
1111
```
1212
1. Run the script to create your Azure AD application and configure the code of the sample application accordingly. (Other ways of running the scripts are described below)
1313
```PowerShell
14-
.\AppCreationScripts\Configure.ps1
14+
cd .\AppCreationScripts\
15+
.\Configure.ps1
1516
```
1617
1. Open the Visual Studio solution and click start
1718

@@ -26,6 +27,7 @@ The following paragraphs:
2627
- [Passing credentials](#option-2-non-interactive) to create the app in your home tenant
2728
- [Interactively in a specific tenant](#option-3-interactive-but-create-apps-in-a-specified-tenant)
2829
- [Passing credentials in a specific tenant](#option-4-non-interactive-and-create-apps-in-a-specified-tenant)
30+
- [Passing environment name, for Sovereign clouds](#running-the-script-on-azure-sovereign-clouds)
2931

3032
## Goal of the scripts
3133

@@ -49,7 +51,7 @@ These scripts are:
4951

5052
The `Configure.ps1` will stop if it tries to create an Azure AD application which already exists in the tenant. For this, if you are using the script to try/test the sample, or in DevOps scenarios, you might want to run `Cleanup.ps1` just before `Configure.ps1`. This is what is shown in the steps below.
5153

52-
## How to use the app creation scripts ?
54+
## How to use the app creation scripts?
5355

5456
### Pre-requisites
5557

@@ -107,7 +109,7 @@ Note that the script will choose the tenant in which to create the applications,
107109
108110
#### Option 2 (non-interactive)
109111
110-
When you know the indentity and credentials of the user in the name of whom you want to create the applications, you can use the non-interactive approach. It's more adapted to DevOps. Here is an example of script you'd want to run in a PowerShell Window
112+
When you know the identity and credentials of the user in the name of whom you want to create the applications, you can use the non-interactive approach. It's more adapted to DevOps. Here is an example of script you'd want to run in a PowerShell Window
111113
112114
```PowerShell
113115
$secpasswd = ConvertTo-SecureString "[Password here]" -AsPlainText -Force
@@ -144,3 +146,21 @@ $tenantId = "yourTenantIdGuid"
144146
. .\Cleanup.ps1 -Credential $mycreds -TenantId $tenantId
145147
. .\Configure.ps1 -Credential $mycreds -TenantId $tenantId
146148
```
149+
150+
### Running the script on Azure Sovereign clouds
151+
152+
All the four options listed above, can be used on any Azure Sovereign clouds. By default, the script targets `AzureCloud`, but it can be changed using the parameter `-AzureEnvironmentName`.
153+
154+
The acceptable values for this parameter are:
155+
156+
- AzureCloud
157+
- AzureChinaCloud
158+
- AzureUSGovernment
159+
- AzureGermanyCloud
160+
161+
Example:
162+
163+
```PowerShell
164+
. .\Cleanup.ps1 -AzureEnvironmentName "AzureGermanyCloud"
165+
. .\Configure.ps1 -AzureEnvironmentName "AzureGermanyCloud"
166+
```

1. Desktop app calls Web API/AppCreationScripts/Cleanup.ps1

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
param(
33
[PSCredential] $Credential,
44
[Parameter(Mandatory=$False, HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')]
5-
[string] $tenantId
5+
[string] $tenantId,
6+
[Parameter(Mandatory=$False, HelpMessage='Azure environment to use while running the script (it defaults to AzureCloud)')]
7+
[string] $azureEnvironmentName
68
)
79

10+
#Requires -Modules AzureAD
11+
12+
813
if ($null -eq (Get-Module -ListAvailable -Name "AzureAD")) {
914
Install-Module "AzureAD" -Scope CurrentUser
1015
}
@@ -13,10 +18,15 @@ $ErrorActionPreference = "Stop"
1318

1419
Function Cleanup
1520
{
16-
<#
17-
.Description
18-
This function removes the Azure AD applications for the sample. These applications were created by the Configure.ps1 script
19-
#>
21+
if (!$azureEnvironmentName)
22+
{
23+
$azureEnvironmentName = "AzureCloud"
24+
}
25+
26+
<#
27+
.Description
28+
This function removes the Azure AD applications for the sample. These applications were created by the Configure.ps1 script
29+
#>
2030

2131
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
2232
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
@@ -25,17 +35,17 @@ This function removes the Azure AD applications for the sample. These applicatio
2535
# you'll need to sign-in with creds enabling your to create apps in the tenant)
2636
if (!$Credential -and $TenantId)
2737
{
28-
$creds = Connect-AzureAD -TenantId $tenantId
38+
$creds = Connect-AzureAD -TenantId $tenantId -AzureEnvironmentName $azureEnvironmentName
2939
}
3040
else
3141
{
3242
if (!$TenantId)
3343
{
34-
$creds = Connect-AzureAD -Credential $Credential
44+
$creds = Connect-AzureAD -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
3545
}
3646
else
3747
{
38-
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential
48+
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
3949
}
4050
}
4151

1. Desktop app calls Web API/AppCreationScripts/Configure.ps1

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
param(
33
[PSCredential] $Credential,
44
[Parameter(Mandatory=$False, HelpMessage='Tenant ID (This is a GUID which represents the "Directory ID" of the AzureAD tenant into which you want to create the apps')]
5-
[string] $tenantId
5+
[string] $tenantId,
6+
[Parameter(Mandatory=$False, HelpMessage='Azure environment to use while running the script (it defaults to AzureCloud)')]
7+
[string] $azureEnvironmentName
68
)
79

10+
#Requires -Modules AzureAD
11+
812
<#
913
This script creates the Azure AD applications needed for this sample and updates the configuration files
1014
for the visual Studio projects from the data in the Azure AD applications.
@@ -175,6 +179,11 @@ Function ConfigureApplications
175179
so that they are consistent with the Applications parameters
176180
#>
177181
$commonendpoint = "common"
182+
183+
if (!$azureEnvironmentName)
184+
{
185+
$azureEnvironmentName = "AzureCloud"
186+
}
178187

179188
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
180189
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
@@ -183,17 +192,17 @@ Function ConfigureApplications
183192
# you'll need to sign-in with creds enabling your to create apps in the tenant)
184193
if (!$Credential -and $TenantId)
185194
{
186-
$creds = Connect-AzureAD -TenantId $tenantId
195+
$creds = Connect-AzureAD -TenantId $tenantId -AzureEnvironmentName $azureEnvironmentName
187196
}
188197
else
189198
{
190199
if (!$TenantId)
191200
{
192-
$creds = Connect-AzureAD -Credential $Credential
201+
$creds = Connect-AzureAD -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
193202
}
194203
else
195204
{
196-
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential
205+
$creds = Connect-AzureAD -TenantId $tenantId -Credential $Credential -AzureEnvironmentName $azureEnvironmentName
197206
}
198207
}
199208

@@ -202,6 +211,8 @@ Function ConfigureApplications
202211
$tenantId = $creds.Tenant.Id
203212
}
204213

214+
215+
205216
$tenant = Get-AzureADTenantDetail
206217
$tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name
207218

@@ -318,10 +329,10 @@ Function ConfigureApplications
318329
# Update config file for 'client'
319330
$configFile = $pwd.Path + "\..\TodoListClient\App.Config"
320331
Write-Host "Updating the sample code ($configFile)"
321-
ReplaceSetting -configFilePath $configFile -key "ida:Tenant" -newValue $tenantName
322-
ReplaceSetting -configFilePath $configFile -key "ida:ClientId" -newValue $clientAadApplication.AppId
323-
ReplaceSetting -configFilePath $configFile -key "todo:TodoListScope" -newValue ("api://"+$serviceAadApplication.AppId+"/access_as_user")
324-
ReplaceSetting -configFilePath $configFile -key "todo:TodoListBaseAddress" -newValue $serviceAadApplication.HomePage
332+
ReplaceSetting -configFilePath $configFile -key "ida:Tenant" -newValue ($tenantName)
333+
ReplaceSetting -configFilePath $configFile -key "ida:ClientId" -newValue ($clientAadApplication.AppId)
334+
ReplaceSetting -configFilePath $configFile -key "todo:TodoListScope" -newValue (("api://"+$serviceAadApplication.AppId+"/access_as_user"))
335+
ReplaceSetting -configFilePath $configFile -key "todo:TodoListBaseAddress" -newValue ($serviceAadApplication.HomePage)
325336
Write-Host ""
326337
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
327338
Write-Host "IMPORTANT: Please follow the instructions below to complete a few manual step(s) in the Azure portal":

1. Desktop app calls Web API/README-incremental.md

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@ endpoint: Microsoft identity platform
1616
### Table of content
1717

1818
- [About this sample](#about-this-sample)
19-
- [Scenario](#scenario)
20-
- [Overview](#overview)
21-
- [User experience when using this sample](#user-experience-when-using-this-sample)
19+
- [Scenario](#scenario)
20+
- [Overview](#overview)
21+
- [User experience when using this sample](#user-experience-when-using-this-sample)
2222
- [How to run this sample](#how-to-run-this-sample)
23-
- [Step 1: In the downloaded folder](#step-1--in-the-downloaded-folder)
24-
- [Step 2: Register the sample application with your Azure Active Directory tenant](#step-2--register-the-sample-application-with-your-azure-active-directory-tenant)
25-
- [Step 3: Configure the sample to use your Azure AD tenant](#step-3--configure-the-sample-to-use-your-azure-ad-tenant)
26-
- [Step 4: Run the sample](#step-4-run-the-sample)
27-
- [Troubleshooting](#troubleshooting)
23+
- [Step 1: In the downloaded folder](#step-1-in-the-downloaded-folder)
24+
- [Step 2: Register the sample application with your Azure Active Directory tenant](#step-2-register-the-sample-application-with-your-azure-active-directory-tenant)
25+
- [Step 3: Run the sample](#step-3-run-the-sample)
2826
- [How was the code created](#how-was-the-code-created)
2927
- [Choosing which scopes to expose](#choosing-which-scopes-to-expose)
3028
- [Next chapter of the tutorial: the Web API itself calls another downstream Web API](#next-chapter-of-the-tutorial-the-web-api-itself-calls-another-downstream-web-api)
31-
- [How to deploy this sample to Azure](#how-to-deploy-this-sample-to-azure)
3229
- [Community Help and Support](#community-help-and-support)
3330
- [Contributing](#contributing)
3431
- [More information](#more-information)
@@ -76,7 +73,7 @@ cd "1. Desktop app calls Web API"
7673

7774
There are two projects in this sample. Each needs to be separately registered in your Azure AD tenant. To register these projects, you can:
7875

79-
- either follow the steps [Step 2: Register the sample with your Azure Active Directory tenant](#step-2-register-the-sample-with-your-azure-active-directory-tenant) and [Step 3: Configure the sample to use your Azure AD tenant](#choose-the-azure-ad-tenant-where-you-want-to-create-your-applications)
76+
- either follow the steps below for manual registration
8077
- or use PowerShell scripts that:
8178
- **automatically** creates the Azure AD applications and related objects (passwords, permissions, dependencies) for you. Note that this works for Visual Studio only.
8279
- modify the Visual Studio projects' configuration files.
@@ -119,7 +116,6 @@ As a first step you'll need to:
119116

120117
#### Register the service app (TodoListService (active-directory-dotnet-native-aspnetcore-v2))
121118

122-
123119
1. Navigate to the Microsoft identity platform for developers [App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page.
124120
1. Select **New registration**.
125121
1. In the **Register an application page** that appears, enter your application's registration information:
@@ -143,10 +139,10 @@ The first thing that we need to do is to declare the unique [resource](https://d
143139
- Keep **State** as **Enabled**
144140
- Click on the **Add scope** button on the bottom to save this scope.
145141

146-
##### Configure the service app (TodoListService (active-directory-dotnet-native-aspnetcore-v2)) to use your app registration
142+
#### Configure the service app (TodoListService (active-directory-dotnet-native-aspnetcore-v2)) to use your app registration
147143

148144
Open the project in your IDE (like Visual Studio) to configure the code.
149-
>In the steps below, "ClientID" is the same as "Application ID" or "AppId".
145+
>In the steps below, "ClientID" is the same as "Application ID" or "AppId".
150146
151147
1. Open the `TodoListService\appsettings.json` file
152148
2. Find the app key `Domain` and replace the existing value with your Azure AD tenant name.
@@ -165,7 +161,6 @@ Open the project in your IDE (like Visual Studio) to configure the code.
165161
1. In the app's registration screen, select **Authentication** in the menu.
166162
- If you don't have a platform added, select **Add a platform** and select the **Public client (mobile & desktop)** option.
167163
- In the **Redirect URIs** | **Suggested Redirect URIs for public clients (mobile, desktop)** section, select **https://login.microsoftonline.com/common/oauth2/nativeclient**
168-
169164
1. Select **Save** to save your changes.
170165
1. In the app's registration screen, click on the **API permissions** blade in the left to open the page where we add access to the Apis that your application needs.
171166
- Click the **Add a permission** button and then,
@@ -174,17 +169,17 @@ Open the project in your IDE (like Visual Studio) to configure the code.
174169
- In the **Delegated permissions** section, select the **access_as_user** in the list. Use the search box if necessary.
175170
- Click on the **Add permissions** button at the bottom.
176171

177-
##### Configure the client app (TodoListClient (active-directory-dotnet-native-aspnetcore-v2)) to use your app registration
172+
#### Configure the client app (TodoListClient (active-directory-dotnet-native-aspnetcore-v2)) to use your app registration
178173

179174
Open the project in your IDE (like Visual Studio) to configure the code.
180-
>In the steps below, "ClientID" is the same as "Application ID" or "AppId".
175+
>In the steps below, "ClientID" is the same as "Application ID" or "AppId".
181176
1. Open the `TodoListClient\App.Config` file
182-
1. Find the app key `ida:Tenant` and replace the existing value with your Azure AD tenant name.
183-
1. Find the app key `ida:ClientId` and replace the existing value with the application ID (clientId) of the `TodoListClient (active-directory-dotnet-native-aspnetcore-v2)` application copied from the Azure portal.
184-
1. Find the app key `todo:TodoListScope` and replace the existing value with Scope.
185-
1. Find the app key `todo:TodoListBaseAddress` and replace the existing value with the base address of the TodoListService (active-directory-dotnet-native-aspnetcore-v2) project (by default `https://localhost:44351/`).
177+
2. Find the app key `ida:Tenant` and replace the existing value with your Azure AD tenant name.
178+
3. Find the app key `ida:ClientId` and replace the existing value with the application ID (clientId) of the `TodoListClient (active-directory-dotnet-native-aspnetcore-v2)` application copied from the Azure portal.
179+
4. Find the app key `todo:TodoListScope` and replace the existing value with Scope.
180+
5. Find the app key `todo:TodoListBaseAddress` and replace the existing value with the base address of the TodoListService (active-directory-dotnet-native-aspnetcore-v2) project (by default `https://localhost:44351/`).
186181

187-
### Step 4: Run the sample
182+
### Step 3: Run the sample
188183

189184
Clean the solution, rebuild the solution, and run it. You might want to go into the solution properties and set both projects as startup projects, with the service project starting first.
190185

@@ -340,7 +335,7 @@ See [2. Web API now calls Microsoft Graph](../2.%20Web%20API%20now%20calls%20Mic
340335

341336
Use [Stack Overflow](http://stackoverflow.com/questions/tagged/msal) to get support from the community.
342337
Ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before.
343-
Make sure that your questions or comments are tagged with [`msal` `dotnet`].
338+
Make sure that your questions or comments are tagged with [`azure-active-directory` `msal` `dotnet`].
344339

345340
To provide a recommendation, visit the following [User Voice page](https://feedback.azure.com/forums/169401-azure-active-directory).
346341

0 commit comments

Comments
 (0)