aspnet mvc 使用 OAUTH2 自定义提供程序对用户进行身份验证

aspnet mvc authenticate users using OAUTH2 custom provider

我有一个 MVC 应用程序,它使用本地 AD 对用户进行身份验证并获取他们的角色以设置对应用程序的权限。现在我有一个新要求,我将使用外部 AD 来验证用户而不是本地 AD。因此,我的应用程序会将用户重定向到客户端的登录页面,用户将输入将在其 AD 上验证的用户名和密码,然后使用令牌重定向回我的应用程序。我需要获取此令牌并再次 post 到客户端点以获得 JWT 令牌。

问题是我找不到类似的好例子。我正在尝试使用 Open Id:

        app.UseOpenIdConnectAuthentication(new 

OpenIdConnectAuthenticationOptions {
                ClientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                Authority = "https://xx.xxxxxxxxx.xxx/adfs/oauth2/authorize",
                RedirectUri = "http://localhost:27100/token",
                ResponseType = "code",
                Scope = "openid email",
                Resource = "xxxxxxxx",
                UseTokenLifetime = false,
                SignInAsAuthenticationType = "Cookies",
            });

但我收到以下错误:

Unable to create to obtain configuration from: 'https://xx.xxxxxxxxx.xxx/adfs/oauth2/authorize/.well-known/openid-configuration

如果我在本地浏览器上打开完整的 url,我可以看到客户 AD 的登录页面。我不确定 OpenIdAuthentication 是否适合这种情况,我正在尝试这个,因为它具有我需要设置的所有属性。还有其他方法可以实现吗?

.well-know/openid-configuration 端点应解析为如下所示的内容:

您可能只需将 Authority 属性 更新为这些值之一(取决于 STS 运行 的位置):

您是否正在尝试代为进行身份验证? 参考https://technet.microsoft.com/en-us/windows-server-docs/identity/ad-fs/development/ad-fs-on-behalf-of-authentication-in-windows-server-2016

OpenID Connect with AD FS 请参考https://technet.microsoft.com/en-us/windows-server-docs/identity/ad-fs/development/enabling-openid-connect-with-ad-fs-2016