Skip to content

Commit 5f0986c

Browse files
author
Kalyan Krishna
committed
Minor edits and deployment related updates
1 parent dd39fd5 commit 5f0986c

File tree

6 files changed

+52
-22
lines changed

6 files changed

+52
-22
lines changed

4-WebApp-your-API/4-1-MyOrg/AppCreationScripts-withCert/Configure.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,20 @@ Function ConfigureApplications
334334
New-MgApplicationOwnerByRef -ApplicationId $clientAadApplication.Id -BodyParameter = @{"@odata.id" = "htps://graph.microsoft.com/v1.0/directoryObjects/$user.ObjectId"}
335335
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($clientServicePrincipal.DisplayName)'"
336336
}
337+
338+
# Add Claims
339+
340+
$optionalClaims = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaims
341+
$optionalClaims.AccessToken = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaim]
342+
$optionalClaims.IdToken = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaim]
343+
$optionalClaims.Saml2Token = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaim]
344+
345+
346+
# Add Optional Claims
347+
348+
$newClaim = CreateOptionalClaim -name "acct"
349+
$optionalClaims.IdToken += ($newClaim)
350+
Update-MgApplication -ApplicationId $clientAadApplication.Id -OptionalClaims $optionalClaims
337351
Write-Host "Done creating the client application (TodoListClient-aspnetcore-webapi)"
338352

339353
# URL of the AAD application in the Azure portal

4-WebApp-your-API/4-1-MyOrg/AppCreationScripts-withCert/sample.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
"DelegatedPermissions": [ "ToDoList.Read", "ToDoList.ReadWrite" ]
125125
}
126126
],
127+
"OptionalClaims": {
128+
"IdTokenClaims": [ "acct" ]
129+
},
127130
"Certificate":"the name will be assigned automatically by PowerShell script and it will be equal to the Application name",
128131
"ManualSteps": [],
129132
"Sample": {

4-WebApp-your-API/4-1-MyOrg/AppCreationScripts/Configure.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,20 @@ Function ConfigureApplications
324324
New-MgApplicationOwnerByRef -ApplicationId $clientAadApplication.Id -BodyParameter = @{"@odata.id" = "htps://graph.microsoft.com/v1.0/directoryObjects/$user.ObjectId"}
325325
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($clientServicePrincipal.DisplayName)'"
326326
}
327+
328+
# Add Claims
329+
330+
$optionalClaims = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaims
331+
$optionalClaims.AccessToken = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaim]
332+
$optionalClaims.IdToken = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaim]
333+
$optionalClaims.Saml2Token = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaim]
334+
335+
336+
# Add Optional Claims
337+
338+
$newClaim = CreateOptionalClaim -name "acct"
339+
$optionalClaims.IdToken += ($newClaim)
340+
Update-MgApplication -ApplicationId $clientAadApplication.Id -OptionalClaims $optionalClaims
327341
Write-Host "Done creating the client application (TodoListClient-aspnetcore-webapi)"
328342

329343
# URL of the AAD application in the Azure portal

4-WebApp-your-API/4-1-MyOrg/AppCreationScripts/sample.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
"DelegatedPermissions": [ "ToDoList.Read", "ToDoList.ReadWrite" ]
127127
}
128128
],
129+
"OptionalClaims": {
130+
"IdTokenClaims": [ "acct" ]
131+
},
129132
"ManualSteps": [],
130133
"Sample": {
131134
"SampleSubPath": "4-WebApp-Your-API\\4-1-MyOrg",
@@ -138,7 +141,7 @@
138141
This section describes how to update the code in configuration files from the apps coordinates, once the apps
139142
are created in Azure AD.
140143
Each section describes a configuration file, for one of the apps, it's type (XML, JSon, plain text), its location
141-
with respect to the root of the sample, and the mappping (which string in the config file is mapped to which value
144+
with respect to the root of the sample, and the mapping (which string in the config file is mapped to which value
142145
*/
143146
"CodeConfiguration": [
144147
{

4-WebApp-your-API/4-1-MyOrg/Client/TodoListClient.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@
2727
<ProjectReference Include="..\TodoListService\TodoListService.csproj" />
2828
</ItemGroup>
2929

30+
<PropertyGroup>
31+
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
32+
</PropertyGroup>
33+
3034
</Project>

4-WebApp-your-API/4-1-MyOrg/README.md

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ To manually register the apps, as a first step you'll need to:
157157
1. Still on the same app registration, select the **Token configuration** blade to the left.
158158
1. Select **Add optional claim**:
159159
1. Select **optional claim type**, then choose **Access**.
160-
1. Select the optional claim **idtyp**.
160+
1. Select the optional claim **idtyp**. Indicates token type.This claim is the most accurate way for an API to determine if a token is an app token or an app+user token
161161
1. Select **Add** to save your changes.
162162
163163
##### Configure the service app (TodoListService-aspnetcore-webapi) to use your app registration
@@ -167,8 +167,8 @@ Open the project in your IDE (like Visual Studio or Visual Studio Code) to confi
167167
> In the steps below, "ClientID" is the same as "Application ID" or "AppId".
168168
169169
1. Open the `TodoListService\appsettings.json` file.
170-
1. Find the key `Domain` and replace the existing value with your Azure AD tenant name.
171-
1. Find the key `TenantId` and replace the existing value with your Azure AD tenant ID.
170+
1. Find the key `Domain` and replace the existing value with your Azure AD tenant domain, ex. `contoso.onmicrosoft.com`.
171+
1. Find the key `TenantId` and replace the existing value with your Azure AD tenant/directory ID.
172172
1. Find the key `ClientId` and replace the existing value with the application ID (clientId) of `TodoListService-aspnetcore-webapi` app copied from the Azure portal.
173173
174174
#### Register the client app (TodoListClient-aspnetcore-webapi)
@@ -203,15 +203,23 @@ Open the project in your IDE (like Visual Studio or Visual Studio Code) to confi
203203
1. In the **Delegated permissions** section, select the **ToDoList.Read**, **ToDoList.ReadWrite** in the list. Use the search box if necessary.
204204
1. Select the **Add permissions** button at the bottom.
205205
206+
##### Configure Optional Claims
207+
208+
1. Still on the same app registration, select the **Token configuration** blade to the left.
209+
1. Select **Add optional claim**:
210+
1. Select **optional claim type**, then choose **ID**.
211+
1. Select the optional claim **acct**. Provides user's account status in tenant.If the user is a member of the tenant, the value is 0. If they're a guest, the value is 1.
212+
1. Select **Add** to save your changes.
213+
206214
##### Configure the client app (TodoListClient-aspnetcore-webapi) to use your app registration
207215
208216
Open the project in your IDE (like Visual Studio or Visual Studio Code) to configure the code.
209217
210218
> In the steps below, "ClientID" is the same as "Application ID" or "AppId".
211219
212220
1. Open the `Client\appsettings.json` file.
213-
1. Find the key `Domain` and replace the existing value with your Azure AD tenant name.
214-
1. Find the key `TenantId` and replace the existing value with your Azure AD tenant ID.
221+
1. Find the key `Domain` and replace the existing value with your Azure AD tenant domain, ex. `contoso.onmicrosoft.com`.
222+
1. Find the key `TenantId` and replace the existing value with your Azure AD tenant/directory ID.
215223
1. Find the key `ClientId` and replace the existing value with the application ID (clientId) of `TodoListClient-aspnetcore-webapi` app copied from the Azure portal.
216224
1. Find the key `ClientSecret` and replace the existing value with the key you saved during the creation of `TodoListClient-aspnetcore-webapi` copied from the Azure portal.
217225
1. Find the key `TodoListScopes` and replace the existing value with **"api://<your_service_api_client_id>/ToDoList.Read api://<your_service_api_client_id>/ToDoList.ReadWrite"**.
@@ -519,14 +527,6 @@ Follow the link to [Publish with Visual Studio](https://docs.microsoft.com/visua
519527
1. Install the Visual Studio Code extension [Azure App Service](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureappservice).
520528
1. Follow the link to [Publish with Visual Studio Code](https://docs.microsoft.com/aspnet/core/tutorials/publish-to-azure-webapp-using-vscode)
521529
522-
#### Enable cross-origin resource sharing (CORS) (TodoListService-aspnetcore-webapi)
523-
524-
> :warning: the following steps are required only if you want your web API to be consumed by a single-page application (SPA). Learn more on [cross-origin resource sharing](https://developer.mozilla.org/docs/Web/HTTP/CORS).
525-
526-
1. Go to [Azure portal](https://portal.azure.com), and locate your project there.
527-
- On the API tab, select **CORS**. Check the box **Enable Access-Control-Allow-Credentials**.
528-
- Under **Allowed origins**, add the site URL of your published website **that will call this web API**.
529-
530530
### Deploying web app to Azure App Services
531531

532532
There is one web app in this sample. To deploy it to **Azure App Services**, you'll need to:
@@ -564,14 +564,6 @@ In the left-hand navigation pane, select the **Azure Active Directory** service,
564564
565565
> :warning: If your app is using an *in-memory* storage, **Azure App Services** will spin down your web site if it is inactive, and any records that your app was keeping will emptied. In addition, if you increase the instance count of your website, requests will be distributed among the instances. Your app's records, therefore, will not be the same on each instance.
566566

567-
## Next Steps
568-
569-
Learn how to:
570-
571-
* [Change your app to sign-in users from any organization or Microsoft accounts](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC/1-3-AnyOrgOrPersonal)
572-
* [Enable users from National clouds to sign-in to your application](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC/1-4-Sovereign)
573-
* [Enable your web app to call a web API on behalf of the signed-in user](https://github.com/Azure-Samples/ms-identity-dotnetcore-ca-auth-context-app)
574-
575567
## Contributing
576568

577569
If you'd like to contribute to this sample, see [CONTRIBUTING.MD](/CONTRIBUTING.md).

0 commit comments

Comments
 (0)