gpt4 book ai didi

asp.net - ASP.NET MVC 不处理 OpenIdConnect signin-oidc 路由

转载 作者:行者123 更新时间:2023-12-03 14:16:56 30 4
gpt4 key购买 nike

我正在使用外部 OIDC 身份提供商将我的用户登录到我的网上商店。该网店基于 ASP.NET MVC 和 .NET Framework 4.7.2 构建。

我已经开始使用基本的 MVC 模板并添加我的身份验证代码。

public void ConfigureAuth(IAppBuilder app)
{

JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();// = new Dictionary<string, string>();

app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType
});

var authority = "https://authentication.myOpenIdProvider.com/auth/oauth2/realms/root/realms/test";
var redirectUri = "http://localhost:8888/signin-oidc";
var postlogoUri = "http://localhost:8888/signout-callback-oidc";
var clientId = "MyClientId";
var clientSecret = "MyClientSecret";

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
ClientSecret = clientSecret,
Authority = authority,
RedirectUri = redirectUri,
PostLogoutRedirectUri = postlogoUri,
ResponseType = "code",
Scope = "openid favorites",
SignInAsAuthenticationType = "Cookies",
RequireHttpsMetadata = false,
});
}

当我在我的页面上点击登录时,我被重定向到我的身份验证提供程序,同时传递了正确的 redirectUri。
public class AccountController : Controller
{
public ActionResult Login()
{
if (!HttpContext.User.Identity.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationType);
return new HttpUnauthorizedResult();
}

return RedirectToAction("Index", "Home");
}

...
}

但是,在我成功地通过我的外部提供商进行身份验证并被重定向到我的站点(目前它只是 http://localhost:8888/signin-oidc 用于开发目的)之后,该路由没有被处理。我收到了 404,所以很明显有些事情没有像它应该做的那样工作。

我已经安装了 ELMAH 并且报告了以下异常消息:

System.Web.HttpException (0x80004005): The controller for path '/signin-oidc' was not found or does not implement IController.



对于上下文:同样适用于 ASP.NET Core API,使用具有相同配置的相同外部 openid 提供程序。

最佳答案

对于将来浏览此内容的任何人,这就是答案:
Owin.OpenIdConnect不支持"code"只有ResponseTypes .您需要设置"id_token"也。如果由于任何原因你不能这样做,你基本上需要自己实现规范的一部分(主要是通过连接到 MessageReceived 通知事件)。

在 OpenIdConnect Handler 的源代码中查看这部分:

https://github.com/aspnet/AspNetKatana/blob/0f6dc4bf2722fb08759da3eacaf38f2a098771bd/src/Microsoft.Owin.Security.OpenIdConnect/OpenidConnectAuthenticationHandler.cs#L258-L264

关于asp.net - ASP.NET MVC 不处理 OpenIdConnect signin-oidc 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56471854/

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