Skip to content

Commit 23f558d

Browse files
author
Kalyan Krishna
committed
Fixes to signout
Fixes to readme about guest account OnRedirectToIdentityProviderForSignOut code merged in AddMsal() as Add Msal() was overwriting the earlier delegate
1 parent fdb4ab5 commit 23f558d

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

2-WebApp-graph-user/2-2-TokenCache/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Starting from a .NET Core 2.2 MVC Web app that uses OpenID Connect to sign in us
1818

1919
It leverages the ASP.NET Core OpenID Connect middleware and Microsoft Authentication Library for .NET (MSAL.NET). The complexities of the library's integration with the ASP.NET Core dependency Injection patterns is encapsultated into the `Microsoft.Identity.Web` library project, which is a part of this tutorial.
2020

21-
![Sign in with the Microsoft identity platform for developers (fomerly Azure AD v2.0)](ReadmeFiles/sign-in.png)
21+
![Sign in with the Microsoft identity platform for developers (formerly Azure AD v2.0)](ReadmeFiles/sign-in.png)
2222

2323
## How to run this sample
2424

5-WebApp-AuthZ/5-1-Roles/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ This sample application defines the following two *Application Roles*:
4141

4242
These application roles are defined in the [Azure portal](https://portal.azure.com) in the application's registration manifest. When a user signs into the application, Azure AD emits a `roles` claim for each role that the user has been granted individually to the user in the from of role membership. Assignment of users and groups to roles can be done through the portal's UI, or programmatically using the [Microsoft Graph](https://graph.microsoft.com) and [Azure AD PowerShell](https://docs.microsoft.com/en-us/powershell/module/azuread/?view=azureadps-2.0). In this sample, application role management is done through the Azure portal or using PowerShell.
4343

44-
NOTE: Role claims are not currently emitted for guest users in a tenant
44+
NOTE: Role claims will not be present for guest users in a tenant if the `/common` endpoint is used as the authority.
4545

4646
![Sign in with the Microsoft identity platform for developers (formerly Azure AD v2.0)](ReadmeFiles/sign-in.png)
4747

Microsoft.Identity.Web/Client/TokenAcquisition.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ public async Task RemoveAccount(RedirectContext context)
255255
account = accounts.FirstOrDefault(a => a.Username == user.GetLoginHint());
256256
}
257257

258-
// this.AppTokenCacheProvider?.Clear();
259-
this.UserTokenCacheProvider?.Clear();
258+
this.UserTokenCacheProvider?.Clear();
260259

261260
await app.RemoveAsync(account);
262261
}

Microsoft.Identity.Web/StartupHelpers.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.Identity.Web.Resource;
88
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
99
using System.Collections.Generic;
10+
using System.Diagnostics;
1011
using System.Threading.Tasks;
1112

1213
namespace Microsoft.Identity.Web
@@ -51,17 +52,6 @@ public static IServiceCollection AddAzureAdV2Authentication(this IServiceCollect
5152
// and [Access Tokens](https://docs.microsoft.com/en-us/azure/active-directory/develop/access-tokens)
5253
options.TokenValidationParameters.NameClaimType = "preferred_username";
5354

54-
// Handling the sign-out: removing the account from MSAL.NET cache
55-
options.Events.OnRedirectToIdentityProviderForSignOut = async context =>
56-
{
57-
var user = context.HttpContext.User;
58-
59-
// Avoid displaying the select account dialog
60-
context.ProtocolMessage.LoginHint = user.GetLoginHint();
61-
context.ProtocolMessage.DomainHint = user.GetDomainHint();
62-
await Task.FromResult(0);
63-
};
64-
6555
// Avoids having users being presented the select account dialog when they are already signed-in
6656
// for instance when going through incremental consent
6757
options.Events.OnRedirectToIdentityProvider = context =>
@@ -72,7 +62,7 @@ public static IServiceCollection AddAzureAdV2Authentication(this IServiceCollect
7262
context.ProtocolMessage.LoginHint = login;
7363
context.ProtocolMessage.DomainHint = context.Properties.GetParameter<string>(OpenIdConnectParameterNames.DomainHint);
7464

75-
// delete the loginhint and domainHint from the Properties when we are done otherwise
65+
// delete the login_hint and domainHint from the Properties when we are done otherwise
7666
// it will take up extra space in the cookie.
7767
context.Properties.Parameters.Remove(OpenIdConnectParameterNames.LoginHint);
7868
context.Properties.Parameters.Remove(OpenIdConnectParameterNames.DomainHint);
@@ -87,7 +77,7 @@ public static IServiceCollection AddAzureAdV2Authentication(this IServiceCollect
8777

8878
return Task.FromResult(0);
8979
};
90-
80+
9181
// If you want to debug, or just understand the OpenIdConnect events, just
9282
// uncomment the following line of code
9383
// OpenIdConnectMiddlewareDiagnostics.Subscribe(options.Events);
@@ -140,6 +130,12 @@ public static IServiceCollection AddMsal(this IServiceCollection services, IEnum
140130
// Remove the account from MSAL.NET token cache
141131
var _tokenAcquisition = context.HttpContext.RequestServices.GetRequiredService<ITokenAcquisition>();
142132
await _tokenAcquisition.RemoveAccount(context);
133+
134+
var user = context.HttpContext.User;
135+
136+
// Avoid displaying the select account dialog
137+
context.ProtocolMessage.LoginHint = user.GetLoginHint();
138+
context.ProtocolMessage.DomainHint = user.GetDomainHint();
143139
};
144140
});
145141
return services;

0 commit comments

Comments
 (0)