Skip to content

Commit f6ad191

Browse files
authored
Update Microsoft Identity Web to 0.2.2-preview. (#155)
1 parent 6891df5 commit f6ad191

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

1. Desktop app calls Web API/TodoListService/TodoListService.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.Identity.Web" Version="0.2.1-preview" />
10+
<PackageReference Include="Microsoft.Identity.Web" Version="0.2.2-preview" />
1111
</ItemGroup>
1212
</Project>

2. Web API now calls Microsoft Graph/README-incremental.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,15 @@ This method:
169169
// we use MSAL.NET to get a token to call the API On Behalf Of the current user
170170
try
171171
{
172-
string accessToken = await tokenAcquisition.GetAccessTokenOnBehalfOfUser(HttpContext, scopes);
172+
string accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(scopes);
173173
dynamic me = await CallGraphApiOnBehalfOfUser(accessToken);
174174
return me.userPrincipalName;
175175
}
176+
catch (MicrosoftIdentityWebChallengeUserException ex)
177+
{
178+
await tokenAcquisition.ReplyForbiddenWithWwwAuthenticateHeaderAsync(scopes, ex.MsalUiRequiredException);
179+
return string.Empty;
180+
}
176181
catch (MsalUiRequiredException ex)
177182
{
178183
await tokenAcquisition.ReplyForbiddenWithWwwAuthenticateHeaderAsync(scopes, ex);

2. Web API now calls Microsoft Graph/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,15 @@ This method:
338338
// we use MSAL.NET to get a token to call the API On Behalf Of the current user
339339
try
340340
{
341-
string accessToken = await tokenAcquisition.GetAccessTokenOnBehalfOfUser(HttpContext, scopes);
341+
string accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(scopes);
342342
dynamic me = await CallGraphApiOnBehalfOfUser(accessToken);
343343
return me.userPrincipalName;
344344
}
345+
catch (MicrosoftIdentityWebChallengeUserException ex)
346+
{
347+
await tokenAcquisition.ReplyForbiddenWithWwwAuthenticateHeaderAsync(scopes, ex.MsalUiRequiredException);
348+
return string.Empty;
349+
}
345350
catch (MsalUiRequiredException ex)
346351
{
347352
await tokenAcquisition.ReplyForbiddenWithWwwAuthenticateHeaderAsync(scopes, ex);
@@ -354,7 +359,7 @@ This method:
354359

355360
#### On the Web API side
356361

357-
An interesting piece is how `MsalUiRequiredException` are handled. These exceptions are typically sent by Azure AD when there is a need for a user interaction. This can be the case when the user needs to re-sign-in, or needs to grant some additional consent, or to obtain additional claims. For instance, the user might need to do multi-factor authentication required specifically by a specific downstream API. When these exceptions happen, given that the Web API does not have any UI, it needs to challenge the client app passing all the required information, so this client app can handle the interaction with the user.
362+
An interesting piece is how `MicrosoftIdentityWebChallengeUserException` are handled. These exceptions are typically sent by Azure AD when there is a need for a user interaction. This can be the case when the user needs to re-sign-in, or needs to grant some additional consent, or to obtain additional claims. For instance, the user might need to do multi-factor authentication required specifically by a specific downstream API. When these exceptions happen, given that the Web API does not have any UI, it needs to challenge the client app passing all the required information, so this client app can handle the interaction with the user.
358363

359364
This sample uses the `ReplyForbiddenWithWwwAuthenticateHeaderAsync` available on the `TokenAcquisition` service (part of Microsoft.Identity.Web library), which uses the HttpResponse to:
360365

2. Web API now calls Microsoft Graph/TodoListService/Controllers/TodoListController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ public async Task<string> CallGraphApiOnBehalfOfUser()
9797
dynamic me = await CallGraphApiOnBehalfOfUser(accessToken);
9898
return me.UserPrincipalName;
9999
}
100+
catch (MicrosoftIdentityWebChallengeUserException ex)
101+
{
102+
await _tokenAcquisition.ReplyForbiddenWithWwwAuthenticateHeaderAsync(scopes, ex.MsalUiRequiredException);
103+
return string.Empty;
104+
}
100105
catch (MsalUiRequiredException ex)
101106
{
102107
await _tokenAcquisition.ReplyForbiddenWithWwwAuthenticateHeaderAsync(scopes, ex);

2. Web API now calls Microsoft Graph/TodoListService/TodoListService.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Identity.Web" Version="0.2.1-preview" />
14+
<PackageReference Include="Microsoft.Identity.Web" Version="0.2.2-preview" />
1515
<PackageReference Include="Microsoft.Graph" Version="3.8.0" />
1616
</ItemGroup>
1717

4.-Console-app-calls-web-API-with-PoP/Microsoft.Identity.Web.Future/Microsoft.Identity.Web.Future.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
</PropertyGroup>
4242

4343
<ItemGroup>
44-
<PackageReference Include="Microsoft.Identity.Web" Version="0.2.1-preview" />
44+
<PackageReference Include="Microsoft.Identity.Web" Version="0.2.2-preview" />
4545
<PackageReference Include="Microsoft.IdentityModel.Protocols.SignedHttpRequest" Version="6.7.1" />
4646
<PackageReference Include="System.Collections" Version="4.3.0" />
4747
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="6.7.1" />

0 commit comments

Comments
 (0)