大网数据广告活动
域与目录服务

Bypass User Selection Prompt When Signing Out of OpenID Connect/OAuth2 Applications

· 52CE 我爱测

Describes how to sign out of an OpenID Connect/OAuth2 application without a user selection prompt.

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

  1. Sign in to the Microsoft Entra admin center as at least a Cloud Application Administrator.
  2. Browse to Entra ID > App registrations.
  3. Select the application for which you want to configure optional claims.
    1. Under Manage, select Token configuration.
    2. Select Add optional claim.
    3. Select the token type you want to configure, such as ID.
    4. Select the optional claim login_hint to add.
    5. 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/nativeclient
    

    During the token endpoint call, when you acquire an access token, an id_token is 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/nativeclient
    

    After sign-in, when Microsoft Entra ID redirects back to your application, an id_token is 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.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 06/10/2025
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。