【问题标题】:ASP.NET MVC 4.5.2 connecting to IdentityServer4ASP.NET MVC 4.5.2 连接到 IdentityServer4
【发布时间】:2017-01-31 05:57:34
【问题描述】:

我有一个在 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
});

我在我的项目 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",
        });

如何正确连接到它?

【问题讨论】:

  • IdentityServer4 应用程序的日志说明了什么?添加一些日志记录。
  • 你好,我正在尝试同样的事情......你有没有得到解决?它甚至有用吗?
  • @JalalEl-Shaer 添加了答案。希望对您有所帮助。

标签: asp.net-mvc-5 owin openid-connect identityserver4


【解决方案1】:

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

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

                }
            };
        }

【讨论】:

  • 对我来说,它可以在没有额外的“signin-oidc”到 Uri 的情况下工作。
  • 谢谢!昨天我在这方面浪费了很多时间,现在它终于奏效了!
  • 我试过这个,但我得到一个范围错误; “抱歉,出现错误:invalid_scope”
  • 使用资源所有者密码验证怎么样?
猜你喜欢
  • 1970-01-01
  • 2017-08-07
  • 1970-01-01
  • 2011-10-23
  • 1970-01-01
  • 2021-06-10
  • 1970-01-01
  • 2020-07-06
  • 1970-01-01
相关资源
最近更新 更多