ASP.NET Framework 4.8 / 4.7 通过 OpenId 连接外部 SSO,使用授权代码授予流程连接,在 /signin-oidc 上返回 404

问题描述 投票:0回答:1

我正在尝试使用 OpenIDConnect/Oauth 和授权代码授予请求为 ASP.NET Framework 4.8 项目设置外部 SSO 提供程序 (FusionAuth)。

当带有授权代码的响应来自 sso 服务器时,

/signin-oidc
端点不可用。

我在类似的帖子中发现,中间件可能没有完全配置,需要添加

app.UseAuthentication()
Startup.cs
,但我不知道如何在Framework 4.8上做到这一点

挑战方案好像没有开启。

这是我的启动课程。

Microsoft.Owin.Host.SystemWeb
并安装了其他依赖项。

using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using Owin;

[assembly: OwinStartup(typeof(WebApplication6_Framework.Startup))]

namespace WebApplication6_Framework
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
            app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                CookieName = "MyCookies",
                AuthenticationType = CookieAuthenticationDefaults.AuthenticationType

            });
            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    Authority = "<authority>",
                    ClientId = "<client_id>",
                    ClientSecret = "<client_secren>",
                    RedirectUri = "https://localhost:44309/signin-oidc",

                    SignInAsAuthenticationType = "Cookies",

                    PostLogoutRedirectUri = "https://localhost:44309",

                    Scope = OpenIdConnectScope.OpenIdProfile,

                    ResponseType = "code", // OpenIdConnectResponseType.Code,

                    TokenValidationParameters = new TokenValidationParameters()
                    {
                        ValidateIssuer = false // For test
                    },

                    RequireHttpsMetadata = false
                }
            );
        }

    }

}

404,当我从 SSO 服务器使用授权代码访问

/signin-oidc
端点上的应用程序时。

Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /signin-oidc

尝试了这两种方法,使用控制器上的 [Autorize] 属性和登录控制器中的代码:

public void SignIn()
        {
            if (!Request.IsAuthenticated)
            {
                HttpContext.GetOwinContext().Authentication.Challenge(
                    new AuthenticationProperties { RedirectUri = "https://localhost:44309/signin-oidc" },
                    OpenIdConnectAuthenticationDefaults.AuthenticationType);
            }
        }

在 ASP.NET 6 项目中使用相同的设置,一切正常。

预先感谢您的帮助。

更新:

相同问题但针对以前框架版本的参考:

OpenIdConnect 登录 oidc 路由未由 ASP.NET MVC 处理

https://learn.microsoft.com/en-us/answers/questions/291678/authentication-ticket-value-is-null-in-the-authori.html?page=1&pageSize=10&sort=oldest

这些对我来说仍然不起作用,但它是解决问题原因的一个很好的切入点。

c# asp.net oauth openid-connect .net-4.8
1个回答
0
投票

请勿在控制器端点中将重定向 uri 设置为 https://localhost:44309/signin-oidc。重定向到请求来源或主页

© www.soinside.com 2019 - 2024. All rights reserved.