连接到IdentityServer4的ASP.NET MVC 4.5.2 [英] ASP.NET MVC 4.5.2 connecting to IdentityServer4

查看:469
本文介绍了连接到IdentityServer4的ASP.NET MVC 4.5.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a website running on ASP.NET MVC 4.5.2. I have an IdentityServer4 server running but when I try and authenticate against it I get an:

invalid_request

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

For ASP.NET Core MVC the documentation has:

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程序包.我的代码如下:

I am including the following NuGet package in my project Microsoft.Owin.Security.OpenIdConnect. My code is as follows:

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

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

            ClientId = "mvc",
        });

一个人如何正确连接到它?

How would one correctly connect to it?

推荐答案

好的,我已经开始工作了.

OK I got this working.

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

You need to add the following NuGet package to your solution 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中的我的客户端"配置为:

My Client config in IdentityServer is:

 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"},

                }
            };
        }

这篇关于连接到IdentityServer4的ASP.NET MVC 4.5.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆