11

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

invalid_request

对于 ASP.NET Core MVC,文档有:

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

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

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

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

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

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

            ClientId = "mvc",
        });

如何正确连接到它?

4

1 回答 1

11

好的,我得到了这个工作。

您需要将以下 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"},

                }
            };
        }
于 2016-09-29T13:15:10.227 回答