gpt4 book ai didi

c# - IDX21323 OpenIdConnectProtocolValidationContext.Nonce 为空,OpenIdConnectProtocolValidatedIdToken.Payload.Nonce 不为空

转载 作者:行者123 更新时间:2023-11-30 20:26:26 25 4
gpt4 key购买 nike

我正在尝试为 Intranet(基于 Orchard CMS)对 Azure AD 和 Graph 进行身份验证,这在我的本地计算机上按预期运行,但是,当访问将成为生产站点的内容时(已经在 ssl 上设置) our internal dns), 我有时会出现上述错误,它相对不一致,我部门的其他人在访问时通常会出现此错误。

我的认证 Controller 如下:

public void LogOn()
{
if (!Request.IsAuthenticated)
{

// Signal OWIN to send an authorization request to Azure.
HttpContext.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}

public void LogOff()
{
if (Request.IsAuthenticated)
{
ClaimsPrincipal _currentUser = (System.Web.HttpContext.Current.User as ClaimsPrincipal);

// Get the user's token cache and clear it.
string userObjectId = _currentUser.Claims.First(x => x.Type.Equals(ClaimTypes.NameIdentifier)).Value;

SessionTokenCache tokenCache = new SessionTokenCache(userObjectId, HttpContext);
HttpContext.GetOwinContext().Authentication.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
}

SDKHelper.SignOutClient();

HttpContext.GetOwinContext().Authentication.SignOut(
OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
}

我的openid选项配置如下:

AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;

var openIdOptions = new OpenIdConnectAuthenticationOptions
{
ClientId = Settings.ClientId,
Authority = "https://login.microsoftonline.com/common/v2.0",
PostLogoutRedirectUri = Settings.LogoutRedirectUri,
RedirectUri = Settings.LogoutRedirectUri,
Scope = "openid email profile offline_access " + Settings.Scopes,
TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = false,
},
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthorizationCodeReceived = async (context) =>
{
var claim = ClaimsPrincipal.Current;
var code = context.Code;

string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;


TokenCache userTokenCache = new SessionTokenCache(signedInUserID,
context.OwinContext.Environment["System.Web.HttpContextBase"] as HttpContextBase).GetMsalCacheInstance();
ConfidentialClientApplication cca = new ConfidentialClientApplication(
Settings.ClientId,
Settings.LogoutRedirectUri,
new ClientCredential(Settings.AppKey),
userTokenCache,
null);


AuthenticationResult result = await cca.AcquireTokenByAuthorizationCodeAsync(code, Settings.SplitScopes.ToArray());
},
AuthenticationFailed = (context) =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
};

var cookieOptions = new CookieAuthenticationOptions();
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseCookieAuthentication(cookieOptions);

app.UseOpenIdConnectAuthentication(openIdOptions);

重定向 url 在 apps.dev.microsoft.com 和我们的本地化 Web 配置中保持一致。

最佳答案

就我而言,这是一个非常奇怪的问题,因为它并没有发生在每个人身上,只有少数客户和开发人员遇到过这个问题。

如果您仅在 chrome(或具有相同引擎的浏览器)中遇到此问题,您可以尝试将 chrome 上的此标志设置为禁用。

enter image description here

这里发生的是 chrome 具有不同的安全规则,即“如果没有 SameSite 限制的 cookie 设置为没有 Secure 属性,它将被拒绝”。因此,您可以禁用此规则,它会起作用。

或者,您也可以设置 Secure 属性,但我不知道该怎么做;(

关于c# - IDX21323 OpenIdConnectProtocolValidationContext.Nonce 为空,OpenIdConnectProtocolValidatedIdToken.Payload.Nonce 不为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49944071/

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