gpt4 book ai didi

c# - MSAL.net prompt=select_account/forcelogin

转载 作者:行者123 更新时间:2023-12-04 08:56:54 24 4
gpt4 key购买 nike

我在我的项目中使用 MSAL.net Azure AD 登录。但是当用户已经使用多个 Microsoft 帐户登录一台计算机时,登录时会出现问题。并且在登录应用程序时需要随机帐户。我想限制用户每次点击登录时选择帐户。
Startup.auth.cs 类

public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseCookieAuthentication(new CookieAuthenticationOptions());

// Custom middleware initialization. This is activated when the code obtained from a code_grant is present in the querystring (&code=<code>).
app.UseOAuth2CodeRedeemer(
new OAuth2CodeRedeemerOptions
{
ClientId = AuthenticationConfig.ClientId,
ClientSecret = AuthenticationConfig.ClientSecret,
RedirectUri = AuthenticationConfig.RedirectUri
});

app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
Authority = AuthenticationConfig.Authority,
ClientId = AuthenticationConfig.ClientId,

RedirectUri = AuthenticationConfig.RedirectUri,
PostLogoutRedirectUri = AuthenticationConfig.PostLogoutUrl,
Scope = AuthenticationConfig.BasicSignInScopes,
TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = false
},
Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthorizationCodeReceived = OnAuthorizationCodeReceived,
AuthenticationFailed = OnAuthenticationFailed,
},
CookieManager = new SameSiteCookieManager(
new SystemWebCookieManager())
});
}
登录操作代码:-
 HttpContext.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/account/logincallback" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);

最佳答案

我找到了解决方案。内RedirectToIdentityProvider 需要通过添加 context.ProtocolMessage.SetParameter(<Name>, <Value>) 来设置额外的参数

Notifications = new OpenIdConnectAuthenticationNotifications()
{
RedirectToIdentityProvider = context =>
{
context.ProtocolMessage.SetParameter("prompt", "login");
return Task.FromResult(0);
},

}
};

关于c# - MSAL.net prompt=select_account/forcelogin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63772199/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com