如何解决使用API网关Ocelot时Oidc找不到关联cookie
我正在使用oidc进行身份验证。我正在使用ocelot作为我的主要入口。因此,我将重定向uri添加到了oidc事件设置中。但是,当我更改重定向URL时,我的微服务无法找到正确的关联cookie。
public static void AddOidcAuthentication(this IServiceCollection services,IConfiguration configuration)
{
var oidcConfig = configuration.GetSection<OidcConfiguration>();
services.AddStoreCookieTicketInMemory();
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "oidc";
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultForbidScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,options =>
{
options.Cookie.Name = oidcConfig.CookieName;
options.Cookie.SameSite = SameSiteMode.None;
})
.AddOpenIdConnect("oidc",options => {
options.SignInScheme = "Cookies";
options.Authority = oidcConfig.Authority;
options.RequireHttpsMetadata = false;
options.ClientId = oidcConfig.ClientId;
options.ClientSecret = oidcConfig.ClientSecret;
options.ResponseType = oidcConfig.ResponseType;
options.Scope.Clear();
oidcConfig.Scopes
.ToList()
.ForEach(scope => options.Scope.Add(scope));
options.SaveTokens = true;
options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProvider = context =>
{
context.ProtocolMessage.RedirectUri = "https://localhost:43500/microservice/signin-oidc";
return Task.FromResult(0);
}
};
});
}
登录后,我的应用返回以下错误:
请求启动HTTP / 1.1 POST https:// localhost:44354 / signin-oidc application / x-www-form-urlencoded 8205 [14:55:34 WRN]'.AspNetCore.Correlation.oidc。找不到Cookie'
如果我删除
context.ProtocolMessage.RedirectUri = "https://localhost:43500/microservice/signin-oidc";
我确实可以,但是它确实可以直接加载我的项目,而不是使用位于https:// localhost:43500 /的网关。
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。