同意页面不断重定向回到Indentityserver4 asp.net core 2.2中的登录页面
我在Identityservice和MVC客户端上尝试了不同的配置,但徒劳
我已将代码上传到github上的url下方 https://github.com/Dheerajmentor/IdentityServer4-Problem
MVC客户端启动
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(options => {
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookie")
.AddOpenIdConnect("oidc",options=> {
options.Authority = "https://localhost:44398/";
options.RequireHttpsMetadata = false;
options.ClientId = "mvc";
options.SaveTokens = true;
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
身份服务器启动
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddIdentityServer()
.AddInMemoryClients(APPConfigure.GetClients())
.AddInMemoryIdentityResources(APPConfigure.GetIdentityResource())
.AddInMemoryApiResources(APPConfigure.GetAPIResources())
.AddTestUsers(APPConfigure.GetUsers())
.AddDeveloperSigningCredential();
}
我希望登录成功后会重定向到同意。
答案 0 :(得分:0)
我刚遇到类似的问题。我正在使用https以调试模式运行。删除app.UseHttpsRedirection();为我工作。
答案 1 :(得分:0)
尝试放置app.UseHttpsRedirection();在其他部分 app.UseHttpsRedirection()确保始终将您重定向到https,并且在开发中您可以在http上运行。
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection()
}
app.UseAuthentication();