Summary
By default, when you sign out of an OpenID Connect/OAuth2 application registered in Microsoft Entra ID, you're prompted to select a user account to sign out of, even if only one account is available. This article provides a step-by-step guide to bypass this behavior.
Step 1: Add an optional claim for login_hint
- Sign in to the Microsoft Entra admin center as at least a Cloud Application Administrator.
- Browse to Entra ID > App registrations.
- Select the application for which you want to configure optional claims.
- Under Manage, select Token configuration.
- Select Add optional claim.
- Select the token type you want to configure, such as ID.
- Select the optional claim login_hint to add.
- Select Add.
For more information about adding optional claims, see Configure and manage optional claims in ID tokens, access tokens, and SAML tokens.
Step 2: Ensure the "profile" and "openid" scopes are included in the original sign-in request
Here are two examples of including both the openid and profile OpenID connect scopes in the request URL:
-
If you use the authorization code flow:
https://login.microsoftonline.com/contoso.onmicrosoft.com/oauth2/v2.0/authorize? response_type=code&client_id=<client_id>&scope=openid+user.read+profile&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclientDuring the token endpoint call, when you acquire an access token, an
id_tokenis also returned. -
If you use the implicit flow (not recommended):
https://login.microsoftonline.com/contoso.onmicrosoft.com/oauth2/v2.0/authorize? response_type=id_token&client_id=<client_id>&scope=openid+user.read+profile&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclientAfter sign-in, when Microsoft Entra ID redirects back to your application, an
id_tokenis returned.
In the returned id_token, the value of the login_hint claim is included.
Step 3: Pass the logout_hint parameter in the sign-out request
When you send a sign-out request, pass the logout_hint parameter along with the value of the login_hint claim in the sign-out request:
https://login.microsoftonline.com/contoso.onmicrosoft.com/oauth2/v2.0/logout?
post_logout_redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient
&logout_hint=<login_hint_claim_value>
More information
For applications using Microsoft Authentication Library for JavaScript (MSAL.js), when you send an EndSessionRequest with a user account, MSAL.js automatically sends the logout_hint parameter along with the login_hint claim if detected.
Here's an example code snippet:
logout() {
var account = this.authService.instance.getAllAccounts()[0];
let logoutRequest:EndSessionRequest = {
account: account
};
this.authService.logout(logoutRequest);
}
For applications using Microsoft Identity Web or ASP.NET (Core) OpenID Connect authentication, you can add custom code to set the logout_hint parameter in the sign-out request.
Here's an example code snippet:
services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
// Custom code here.
options.Events.OnRedirectToIdentityProviderForSignOut = (context) =>
{
var login_hint = context.HttpContext.User.Claims.Where(c => c.Type == "login_hint").FirstOrDefault();
if (login_hint != null)
{
context.ProtocolMessage.SetParameter("logout_hint", login_hint.Value);
};
return Task.FromResult(true);
};
});
Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
