Jakeuj's Notes Help

AZURE AD 每次登入都要打帳號密碼

預設是使用單一單入

但有時需求是每次都要重新登入

結論

登入時加上 prompt=login

以 dotnet core OpenIdConnect 為例,加上以下設定

options.Prompt = configuration["AzureAd:Prompt"];

範例程式碼

private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) { context.Services.AddAuthentication() .AddJwtBearer(options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); options.Audience = "MyProject"; }) .AddOpenIdConnect("AzureAdOpenId", "Azure AD OpenId", options => { options.Authority = "https://login.microsoftonline.com/" + configuration["AzureAd:TenantId"] + "/v2.0/"; options.ClientId = configuration["AzureAd:ClientId"]; options.ResponseType = OpenIdConnectResponseType.CodeIdToken; options.CallbackPath = configuration["AzureAd:CallbackPath"]; options.ClientSecret = configuration["AzureAd:ClientSecret"]; options.RequireHttpsMetadata = false; options.SaveTokens = true; options.GetClaimsFromUserInfoEndpoint = true; options.Prompt = configuration["AzureAd:Prompt"]; options.Scope.Add("email"); options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "sub"); }); }

如何驗證登入提示

在有登入工作階段的瀏覽器啟動一次新的 OpenID Connect challenge,再觀察身分提供者是否要求重新驗證。若應用程式直接沿用自己的登入工作階段,這次請求根本不會進到 Microsoft 登入頁,調整 Prompt 也看不到效果。重新驗證時可用的登入方式取決於租用戶原則與使用者的驗證方法。

Microsoft 身分識別平台的 OpenID Connect 登入請求

參照

OAuth 2.0 隱含授與流程-Microsoft 身分識別平臺 | Microsoft Docs

01 December 2026