我使用OpenID Connect构建了一个身份提供程序,以提供利用OAuth2访问令牌的身份验证和授权 . 服务器上的授权工作流程有效;但是,当身份验证失败时,我似乎无法让我的ASP.NET Core客户端自动重定向到OpenID Connect提供程序 . 我目前只收到401 .
这是我的startup.cs:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseCookieAuthentication();
var options = new OpenIdConnectOptions
{
Authority = "http://localhost:63467",
AutomaticAuthenticate = true,
AutomaticChallenge = true,
AuthenticationMethod = OpenIdConnectRedirectBehavior.RedirectGet,
AuthenticationScheme = "oidc",
ClientId = "2",
ClientSecret = "alskghalsd",
Configuration =
new OpenIdConnectConfiguration
{
AuthorizationEndpoint =
"http://localhost:63467/connect/authorize",
TokenEndpoint =
"http://localhost:63467/connect/token"
},
PostLogoutRedirectUri = "/",
ResponseType = "Code",
RemoteSignOutPath = "/signout",
UseTokenLifetime = true,
SaveTokens = true,
SignInScheme = "Cookies",
RequireHttpsMetadata = false
};
options.Scope.AddRange(new[] { "openid name role profile" });
app.UseOpenIdConnectAuthentication(options);
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
1 回答
我最终通过使用IdentityServer将应用程序作为Identity endpoints 托管并相应地配置我的客户端来解决此问题 .
我会等待一段时间,然后将此标记为允许其他人提供替代解决方案的答案 .