Skip to content

Commit 6773309

Browse files
author
Kalyan Krishna
authored
Merge branch 'master' into update-multitenant-routes
2 parents bb47819 + a504ecf commit 6773309

File tree

156 files changed

+78678
-1022
lines changed

Some content is hidden

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

156 files changed

+78678
-1022
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,4 @@ packages
136136
/4-WebApp-your-API/4-1-MyOrg/.vscode/settings.json
137137
/5-WebApp-AuthZ/5-1-Roles/.vscode/settings.json
138138
/.vscode
139+
/2-WebApp-graph-user/2-1-Call-MSGraph/Properties/PublishProfiles

1-WebApp-OIDC/1-1-MyOrg/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<PrivateAssets>all</PrivateAssets>
2525
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2626
</PackageReference>
27-
<PackageReference Include="Microsoft.Identity.Web" Version="1.22.2" />
28-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.22.2" />
27+
<PackageReference Include="Microsoft.Identity.Web" Version="1.25.2" />
28+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.25.2" />
2929
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
3030
</ItemGroup>
3131

1-WebApp-OIDC/1-2-AnyOrg/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.Identity.Web" Version="1.22.2" />
22-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.22.2" />
21+
<PackageReference Include="Microsoft.Identity.Web" Version="1.25.2" />
22+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.25.2" />
2323
</ItemGroup>
2424

2525
</Project>

1-WebApp-OIDC/1-3-AnyOrgOrPersonal/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.Identity.Web" Version="1.22.2" />
22-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.22.2" />
21+
<PackageReference Include="Microsoft.Identity.Web" Version="1.25.2" />
22+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.25.2" />
2323
</ItemGroup>
2424

2525
</Project>

1-WebApp-OIDC/1-4-Sovereign/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.Identity.Web" Version="1.22.2" />
22-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.22.2" />
21+
<PackageReference Include="Microsoft.Identity.Web" Version="1.25.2" />
22+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.25.2" />
2323
</ItemGroup>
2424

2525
</Project>
106 KB
Loading

1-WebApp-OIDC/1-5-B2C/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
6363

6464
app.UseHttpsRedirection();
6565
app.UseStaticFiles();
66-
app.UseCookiePolicy();
6766

6867
app.UseRouting();
6968
app.UseAuthentication();

1-WebApp-OIDC/1-5-B2C/Views/Shared/_CookieConsentPartial.cshtml

Lines changed: 0 additions & 40 deletions
This file was deleted.

1-WebApp-OIDC/1-5-B2C/Views/Shared/_Layout.cshtml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@
3838
</div>
3939
</nav>
4040

41-
<partial name="_CookieConsentPartial" />
42-
4341
<div class="container body-content">
4442
@RenderBody()
4543
<hr />
4644
<footer>
47-
<p>&copy; 2018 - WebApp_OpenIDConnect_DotNet</p>
45+
<p>&copy; 2022 - WebApp_OpenIDConnect_DotNet</p>
4846
</footer>
4947
</div>
5048

1-WebApp-OIDC/1-5-B2C/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.Identity.Web" Version="1.22.2" />
22-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.22.2" />
21+
<PackageReference Include="Microsoft.Identity.Web" Version="1.25.2" />
22+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.25.2" />
2323
</ItemGroup>
2424

2525
</Project>

1-WebApp-OIDC/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ In this chapter of the tutorial, You'll learn how to use the [Microsoft.Identity
2222
## Next chapters
2323

2424
- If you signed-in users with Work or School accounts, or Microsoft personal accounts, you might want to learn how to call an API, starting with [Microsoft Graph](./2-WebApp-graph-user/2-1-Call-MSGraph/README.md).
25-
- If you wish to protect your web APIs using the Microsoft Identity Platform, please look into [call your own Web API directly](./4-WebApp-your-API/4-1-MyOrg/README.md).
25+
- If you wish to protect your web APIs using the Microsoft Identity Platform, please look into [call your own Web API directly](./4-1-MyOrg/README.md).

2-WebApp-graph-user/2-1-Call-MSGraph/ReadmeFiles/AboutTheCode.md

Whitespace-only changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
### Process the CAE challenge from Microsoft Graph
2+
3+
To process the CAE challenge from Microsoft Graph, the controller actions need to extract it from the `wwwAuthenticate` header. It is returned when MS Graph rejects a seemingly valid Access tokens for MS Graph. For this you need to:
4+
5+
1. Inject and instance of `MicrosoftIdentityConsentAndConditionalAccessHandler` in the controller constructor. The beginning of the HomeController becomes:
6+
7+
```CSharp
8+
public class HomeController : Controller
9+
{
10+
private readonly ILogger<HomeController> _logger;
11+
private readonly GraphServiceClient _graphServiceClient;
12+
private readonly MicrosoftIdentityConsentAndConditionalAccessHandler _consentHandler;
13+
private string[] _graphScopes = new[] { "user.read" };
14+
public HomeController(ILogger<HomeController> logger,
15+
IConfiguration configuration,
16+
GraphServiceClient graphServiceClient,
17+
MicrosoftIdentityConsentAndConditionalAccessHandler consentHandler)
18+
{
19+
_logger = logger;
20+
_graphServiceClient = graphServiceClient;
21+
this._consentHandler = consentHandler;
22+
// Capture the Scopes for Graph that were used in the original request for an Access token (AT) for MS Graph as
23+
// they'd be needed again when requesting a fresh AT for Graph during claims challenge processing
24+
_graphScopes = configuration.GetValue<string>("DownstreamApi:Scopes")?.Split(' ');
25+
}
26+
27+
// more code here
28+
```
29+
1. The process to handle CAE challenges from MS Graph comprises of the following steps:
30+
1. Catch a Microsoft Graph SDK's `ServiceException` and extract the required `claims`. This is done by wrapping the call to Microsoft Graph into a try/catch block that processes the challenge:
31+
```CSharp
32+
currentUser = await _graphServiceClient.Me.Request().GetAsync();
33+
```
34+
1. Then redirect the user back to Azure AD with the new requested `claims`. Azure AD will use this `claims` payload to discern what or if any additional processing is required, example being the user needs to sign-in again or do multi-factor authentication.
35+
```CSharp
36+
try
37+
{
38+
currentUser = await _graphServiceClient.Me.Request().GetAsync();
39+
}
40+
// Catch CAE exception from Graph SDK
41+
catch (ServiceException svcex) when (svcex.Message.Contains("Continuous access evaluation resulted in claims challenge"))
42+
{
43+
try
44+
{
45+
Console.WriteLine($"{svcex}");
46+
string claimChallenge = WwwAuthenticateParameters.GetClaimChallengeFromResponseHeaders(svcex.ResponseHeaders);
47+
_consentHandler.ChallengeUser(_graphScopes, claimChallenge);
48+
return new EmptyResult();
49+
}
50+
catch (Exception ex2)
51+
{
52+
_consentHandler.HandleException(ex2);
53+
}
54+
}
55+
```
56+
57+
The `AuthenticationHeaderHelper` class is available from the `Helpers\AuthenticationHeaderHelper.cs file`.

0 commit comments

Comments
 (0)