ASP.NET MVC 4.5.2 连接到 IdentityServer4

ASP.NET MVC 4.5.2 connecting to IdentityServer4

我在 ASP.NET MVC 4.5.2 上有一个网站 运行。我有一个 IdentityServer4 服务器 运行,但是当我尝试对它进行身份验证时,我得到一个:

invalid_request

对于 ASP.NET Core MVC,documentation 具有:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
    AuthenticationScheme = "oidc",
    SignInScheme = "Cookies",

    Authority = "http://localhost:5000",
    RequireHttpsMetadata = false,

    ClientId = "mvc",
    SaveTokens = true
});

我在我的项目中包含以下 NuGet 包 Microsoft.Owin.Security.OpenIdConnect。我的代码如下:

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = "Cookies"
        });
        app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        {
            AuthenticationType = "oidc",
            SignInAsAuthenticationType = "Cookies",

            Authority = "http://localhost:5000",

            ClientId = "mvc",
        });

如何正确连接到它?

好的,我开始工作了。

您需要将以下 NuGet 包添加到您的解决方案中 Microsoft.Owin.Security.OpenIdConnect .

我的Startup.Auth.cs包含

 public void ConfigureAuth(IAppBuilder app)
        {

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

            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                Authority = "http://localhost:5000", //ID Server
                ClientId = "demo",
                ResponseType = "id_token code",
                SignInAsAuthenticationType = "Cookies",
                RedirectUri = "http://localhost:51048/signin-oidc", //URL of website
                Scope = "openid",               
            });

        }

我在 IdentityServer 中的客户端配置是:

 public static IEnumerable<Client> GetClients()
        {
            return new List<Client> {
                new Client {
                    ClientId = "demo",
                    AllowedScopes = new List<string> { "openid"},
                    AllowedGrantTypes = GrantTypes.Hybrid,
                    RedirectUris = new List<string>{"http://localhost:51048/signin-oidc"},

                }
            };
        }