gpt4 book ai didi

openid-connect - 如何覆盖 OpenIdConnectAuthenticationHandler RememberNonce 方法

转载 作者:行者123 更新时间:2023-12-03 17:05:25 26 4
gpt4 key购买 nike

我有一个问题,似乎使用 Office 365 身份验证得到了很好的记录,其中 cookie 对于 header 而言变得太大,因为存储了多个 nonce 消息。
我找到了以下代码,但我无法在身份验证时触发它,所以有人可以帮助我解决我所缺少的问题:

public class SawtoothOpenIdConnectAuthenticationHandler : OpenIdConnectAuthenticationHandler
{
public SawtoothOpenIdConnectAuthenticationHandler(ILogger logger)
: base(logger) { }

protected override void RememberNonce(OpenIdConnectMessage message, string nonce)
{
var oldNonces = Request.Cookies.Where(kvp => kvp.Key.StartsWith(OpenIdConnectAuthenticationDefaults.CookiePrefix + "nonce"));
if (oldNonces.Any())
{
CookieOptions cookieOptions = new CookieOptions
{
HttpOnly = true,
Secure = Request.IsSecure
};
foreach (KeyValuePair<string, string> oldNonce in oldNonces)
{
Response.Cookies.Delete(oldNonce.Key, cookieOptions);
}
}
base.RememberNonce(message, nonce);
}
}

最佳答案

创建一个继承自 OpenIdConnectAuthenticationMiddleware 类的类,该类在 CreateHandler 方法中返回处理程序。

public class SawtoothOpenIdConnectAuthenticationMiddleware : OpenIdConnectAuthenticationMiddleware
{
private readonly ILogger _logger;

public SawtoothOpenIdConnectAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, OpenIdConnectAuthenticationOptions options) : base(next, app, options)
{
_logger = app.CreateLogger<SawtoothOpenIdConnectAuthenticationMiddleware>();
}

protected override AuthenticationHandler<OpenIdConnectAuthenticationOptions> CreateHandler()
{
return new SawtoothOpenIdConnectAuthenticationHandler(_logger);
}
}
然后将中间件添加到 OWIN 运行时中。
例如:
public static IAppBuilder UseSawtoothOpenIdConnectAuthentication(this IAppBuilder app, OpenIdConnectAuthenticationOptions openIdConnectOptions)
{
if (app == null)
{
throw new ArgumentNullException("app");
}

if (openIdConnectOptions == null)
{
throw new ArgumentNullException("openIdConnectOptions");
}

return app.Use(typeof(SawtoothOpenIdConnectAuthenticationMiddleware), app, openIdConnectOptions);
}

关于openid-connect - 如何覆盖 OpenIdConnectAuthenticationHandler RememberNonce 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43604832/

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