Skip to content

Commit 35397bc

Browse files
author
Kalyan Krishna
committed
merged with master
2 parents 2e52559 + 9a790f1 commit 35397bc

File tree

56 files changed

+860
-654
lines changed

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

+860
-654
lines changed

1-WebApp-OIDC/1-1-MyOrg/AppCreationScripts/AppCreationScripts.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Registering the Azure Active Directory applications and updating the configuration files for this sample using PowerShell scripts
1+
# Registering the sample apps with Microsoft identity platform and updating the configuration files using PowerShell scripts
22

33
## Overview
44

@@ -9,9 +9,10 @@
99
```PowerShell
1010
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
1111
```
12-
1. Run the script to create your Azure AD application and configure the code of the sample application accordinly. (Other ways of running the scripts are described below)
12+
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

1-WebApp-OIDC/1-1-MyOrg/AppCreationScripts/Cleanup.ps1

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ param(
55
[string] $tenantId
66
)
77

8-
if ((Get-Module -ListAvailable -Name "AzureAD") -eq $null) {
8+
if ($null -eq (Get-Module -ListAvailable -Name "AzureAD")) {
99
Install-Module "AzureAD" -Scope CurrentUser
1010
}
1111
Import-Module AzureAD
12-
$ErrorActionPreference = 'Stop'
12+
$ErrorActionPreference = "Stop"
1313

1414
Function Cleanup
1515
{
@@ -44,20 +44,27 @@ This function removes the Azure AD applications for the sample. These applicatio
4444
$tenantId = $creds.Tenant.Id
4545
}
4646
$tenant = Get-AzureADTenantDetail
47-
$tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name
47+
$tenantName = ($tenant.VerifiedDomains | Where-Object { $_._Default -eq $True }).Name
4848

4949
# Removes the applications
5050
Write-Host "Cleaning-up applications from tenant '$tenantName'"
5151

5252
Write-Host "Removing 'webApp' (WebApp) if needed"
53-
$app=Get-AzureADApplication -Filter "DisplayName eq 'WebApp'"
53+
Get-AzureADApplication -Filter "DisplayName eq 'WebApp'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
54+
$apps = Get-AzureADApplication -Filter "DisplayName eq 'WebApp'"
55+
if ($apps)
56+
{
57+
Remove-AzureADApplication -ObjectId $apps.ObjectId
58+
}
5459

55-
if ($app)
60+
foreach ($app in $apps)
5661
{
5762
Remove-AzureADApplication -ObjectId $app.ObjectId
58-
Write-Host "Removed."
63+
Write-Host "Removed WebApp.."
5964
}
60-
65+
# also remove service principals of this app
66+
Get-AzureADServicePrincipal -filter "DisplayName eq 'WebApp'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
67+
6168
}
6269

63-
Cleanup -Credential $Credential -tenantId $TenantId
70+
Cleanup -Credential $Credential -tenantId $TenantId

1-WebApp-OIDC/1-1-MyOrg/AppCreationScripts/Configure.ps1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,16 @@ Function UpdateTextFile([string] $configFilePath, [System.Collections.HashTable]
5656
Set-Content -Value "<html><body><table>" -Path createdApps.html
5757
Add-Content -Value "<thead><tr><th>Application</th><th>AppId</th><th>Url in the Azure portal</th></tr></thead><tbody>" -Path createdApps.html
5858

59+
$ErrorActionPreference = "Stop"
60+
5961
Function ConfigureApplications
6062
{
6163
<#.Description
6264
This function creates the Azure AD applications for the sample in the provided Azure AD tenant and updates the
6365
configuration files in the client and service project of the visual studio solution (App.Config and Web.Config)
6466
so that they are consistent with the Applications parameters
6567
#>
68+
$commonendpoint = "common"
6669

6770
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
6871
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
@@ -93,11 +96,12 @@ Function ConfigureApplications
9396
$tenant = Get-AzureADTenantDetail
9497
$tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name
9598

96-
# Get the user running the script
99+
# Get the user running the script to add the user as the app owner
97100
$user = Get-AzureADUser -ObjectId $creds.Account.Id
98101

99102
# Create the webApp AAD application
100103
Write-Host "Creating the AAD application (WebApp)"
104+
# create the application
101105
$webAppAadApplication = New-AzureADApplication -DisplayName "WebApp" `
102106
-HomePage "https://localhost:44321/" `
103107
-LogoutUrl "https://localhost:44321/signout-oidc" `
@@ -106,17 +110,19 @@ Function ConfigureApplications
106110
-Oauth2AllowImplicitFlow $true `
107111
-PublicClient $False
108112

113+
# create the service principal of the newly created application
109114
$currentAppId = $webAppAadApplication.AppId
110115
$webAppServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
111116

112117
# add the user running the script as an app owner if needed
113118
$owner = Get-AzureADApplicationOwner -ObjectId $webAppAadApplication.ObjectId
114119
if ($owner -eq $null)
115120
{
116-
Add-AzureADApplicationOwner -ObjectId $webAppAadApplication.ObjectId -RefObjectId $user.ObjectId
117-
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($webAppServicePrincipal.DisplayName)'"
121+
Add-AzureADApplicationOwner -ObjectId $webAppAadApplication.ObjectId -RefObjectId $user.ObjectId
122+
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($webAppServicePrincipal.DisplayName)'"
118123
}
119124

125+
120126
Write-Host "Done creating the webApp application (WebApp)"
121127

122128
# URL of the AAD application in the Azure portal
@@ -130,14 +136,15 @@ Function ConfigureApplications
130136
Write-Host "Updating the sample code ($configFile)"
131137
$dictionary = @{ "ClientId" = $webAppAadApplication.AppId;"TenantId" = $tenantId;"Domain" = $tenantName };
132138
UpdateTextFile -configFilePath $configFile -dictionary $dictionary
133-
139+
134140
Add-Content -Value "</tbody></table></body></html>" -Path createdApps.html
135141
}
136142

137143
# Pre-requisites
138144
if ((Get-Module -ListAvailable -Name "AzureAD") -eq $null) {
139145
Install-Module "AzureAD" -Scope CurrentUser
140-
}
146+
}
147+
141148
Import-Module AzureAD
142149

143150
# Run interactively (will ask you for the tenant ID)

1-WebApp-OIDC/1-1-MyOrg/Properties/launchSettings.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
},
1010
"profiles": {
1111
"WebApp_OpenIDConnect_DotNet": {
12-
"commandName": "Project",
13-
"launchBrowser": true,
14-
"applicationUrl": "https://localhost:44366;http://localhost:3110",
15-
"environmentVariables": {
16-
"ASPNETCORE_ENVIRONMENT": "Development"
17-
}
12+
"commandName": "Project",
13+
"launchBrowser": true,
14+
"applicationUrl": "https://localhost:44321;http://localhost:3110",
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
1818
}
1919
}
2020
}

1-WebApp-OIDC/1-1-MyOrg/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ There is one project in this sample. To register it, you can:
4848
3. Run the script to create your Azure AD application and configure the code of the sample application accordingly
4949
5050
```PowerShell
51-
.\AppCreationScripts\Configure.ps1
51+
cd .\AppCreationScripts\
52+
.\Configure.ps1
5253
```
5354
5455
> Other ways of running the scripts are described in [App Creation Scripts](./AppCreationScripts/AppCreationScripts.md)

1-WebApp-OIDC/1-2-AnyOrg/AppCreationScripts/AppCreationScripts.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Registering the Azure Active Directory applications and updating the configuration files for this sample using PowerShell scripts
1+
# Registering the sample apps with Microsoft identity platform and updating the configuration files using PowerShell scripts
22

33
## Overview
44

@@ -9,9 +9,10 @@
99
```PowerShell
1010
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
1111
```
12-
1. Run the script to create your Azure AD application and configure the code of the sample application accordinly. (Other ways of running the scripts are described below)
12+
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

1-WebApp-OIDC/1-2-AnyOrg/AppCreationScripts/Cleanup.ps1

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ param(
55
[string] $tenantId
66
)
77

8-
if ((Get-Module -ListAvailable -Name "AzureAD") -eq $null) {
8+
if ($null -eq (Get-Module -ListAvailable -Name "AzureAD")) {
99
Install-Module "AzureAD" -Scope CurrentUser
1010
}
1111
Import-Module AzureAD
12-
$ErrorActionPreference = 'Stop'
12+
$ErrorActionPreference = "Stop"
1313

1414
Function Cleanup
1515
{
@@ -44,20 +44,27 @@ This function removes the Azure AD applications for the sample. These applicatio
4444
$tenantId = $creds.Tenant.Id
4545
}
4646
$tenant = Get-AzureADTenantDetail
47-
$tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name
47+
$tenantName = ($tenant.VerifiedDomains | Where-Object { $_._Default -eq $True }).Name
4848

4949
# Removes the applications
5050
Write-Host "Cleaning-up applications from tenant '$tenantName'"
5151

5252
Write-Host "Removing 'webApp' (WebApp) if needed"
53-
$app=Get-AzureADApplication -Filter "DisplayName eq 'WebApp'"
53+
Get-AzureADApplication -Filter "DisplayName eq 'WebApp'" | ForEach-Object {Remove-AzureADApplication -ObjectId $_.ObjectId }
54+
$apps = Get-AzureADApplication -Filter "DisplayName eq 'WebApp'"
55+
if ($apps)
56+
{
57+
Remove-AzureADApplication -ObjectId $apps.ObjectId
58+
}
5459

55-
if ($app)
60+
foreach ($app in $apps)
5661
{
5762
Remove-AzureADApplication -ObjectId $app.ObjectId
58-
Write-Host "Removed."
63+
Write-Host "Removed WebApp.."
5964
}
60-
65+
# also remove service principals of this app
66+
Get-AzureADServicePrincipal -filter "DisplayName eq 'WebApp'" | ForEach-Object {Remove-AzureADServicePrincipal -ObjectId $_.Id -Confirm:$false}
67+
6168
}
6269

63-
Cleanup -Credential $Credential -tenantId $TenantId
70+
Cleanup -Credential $Credential -tenantId $TenantId

1-WebApp-OIDC/1-2-AnyOrg/AppCreationScripts/Configure.ps1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,16 @@ Function UpdateTextFile([string] $configFilePath, [System.Collections.HashTable]
5656
Set-Content -Value "<html><body><table>" -Path createdApps.html
5757
Add-Content -Value "<thead><tr><th>Application</th><th>AppId</th><th>Url in the Azure portal</th></tr></thead><tbody>" -Path createdApps.html
5858

59+
$ErrorActionPreference = "Stop"
60+
5961
Function ConfigureApplications
6062
{
6163
<#.Description
6264
This function creates the Azure AD applications for the sample in the provided Azure AD tenant and updates the
6365
configuration files in the client and service project of the visual studio solution (App.Config and Web.Config)
6466
so that they are consistent with the Applications parameters
6567
#>
68+
$commonendpoint = "common"
6669

6770
# $tenantId is the Active Directory Tenant. This is a GUID which represents the "Directory ID" of the AzureAD tenant
6871
# into which you want to create the apps. Look it up in the Azure portal in the "Properties" of the Azure AD.
@@ -93,11 +96,12 @@ Function ConfigureApplications
9396
$tenant = Get-AzureADTenantDetail
9497
$tenantName = ($tenant.VerifiedDomains | Where { $_._Default -eq $True }).Name
9598

96-
# Get the user running the script
99+
# Get the user running the script to add the user as the app owner
97100
$user = Get-AzureADUser -ObjectId $creds.Account.Id
98101

99102
# Create the webApp AAD application
100103
Write-Host "Creating the AAD application (WebApp)"
104+
# create the application
101105
$webAppAadApplication = New-AzureADApplication -DisplayName "WebApp" `
102106
-HomePage "https://localhost:44321/" `
103107
-LogoutUrl "https://localhost:44321/signout-oidc" `
@@ -107,17 +111,19 @@ Function ConfigureApplications
107111
-Oauth2AllowImplicitFlow $true `
108112
-PublicClient $False
109113

114+
# create the service principal of the newly created application
110115
$currentAppId = $webAppAadApplication.AppId
111116
$webAppServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
112117

113118
# add the user running the script as an app owner if needed
114119
$owner = Get-AzureADApplicationOwner -ObjectId $webAppAadApplication.ObjectId
115120
if ($owner -eq $null)
116121
{
117-
Add-AzureADApplicationOwner -ObjectId $webAppAadApplication.ObjectId -RefObjectId $user.ObjectId
118-
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($webAppServicePrincipal.DisplayName)'"
122+
Add-AzureADApplicationOwner -ObjectId $webAppAadApplication.ObjectId -RefObjectId $user.ObjectId
123+
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($webAppServicePrincipal.DisplayName)'"
119124
}
120125

126+
121127
Write-Host "Done creating the webApp application (WebApp)"
122128

123129
# URL of the AAD application in the Azure portal
@@ -131,14 +137,15 @@ Function ConfigureApplications
131137
Write-Host "Updating the sample code ($configFile)"
132138
$dictionary = @{ "ClientId" = $webAppAadApplication.AppId;"TenantId" = "organizations";"Domain" = $tenantName };
133139
UpdateTextFile -configFilePath $configFile -dictionary $dictionary
134-
140+
135141
Add-Content -Value "</tbody></table></body></html>" -Path createdApps.html
136142
}
137143

138144
# Pre-requisites
139145
if ((Get-Module -ListAvailable -Name "AzureAD") -eq $null) {
140146
Install-Module "AzureAD" -Scope CurrentUser
141-
}
147+
}
148+
142149
Import-Module AzureAD
143150

144151
# Run interactively (will ask you for the tenant ID)

1-WebApp-OIDC/1-2-AnyOrg/AppCreationScripts/sample.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"Sample": {
3-
"Title": "An ASP.NET Core 2.x Web App which lets sign-in users with work and school in any org",
3+
"Title": "An ASP.NET Core Web App which lets sign-in users with work and school in any org",
44
"Level": 200,
5-
"Client": "ASP.NET Core 2.x Web App",
5+
"Client": "ASP.NET Core Web App",
66
"Service": "Microsoft Graph",
77
"RepositoryUrl": "microsoft-identity-platform-aspnetcore-webapp-tutorial",
88
"Endpoint": "AAD v2.0"
@@ -41,7 +41,7 @@
4141
},
4242
{
4343
"key": "TenantId",
44-
"value": "organizations"
44+
"value": "\"organizations\""
4545
},
4646
{
4747
"key": "Domain",

1-WebApp-OIDC/1-2-AnyOrg/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"WebApp_OpenIDConnect_DotNet": {
1212
"commandName": "Project",
1313
"launchBrowser": true,
14-
"applicationUrl": "https://localhost:44366;http://localhost:3110",
14+
"applicationUrl": "https://localhost:44321;http://localhost:3110",
1515
"environmentVariables": {
1616
"ASPNETCORE_ENVIRONMENT": "Development"
1717
}

0 commit comments

Comments
 (0)