2016-09-22 65 views
10

我有一个运行在ASP.NET MVC 4.5.2上的网站。我有一个IdentityServer4服务器上运行,但是当我尝试和验证反对我得到一个:连接到IdentityServer4的ASP.NET MVC 4.5.2

invalid_request 

对于ASP.NET 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", 
     }); 

如何才能正确连接到它?

+0

什么日志上IdentityServer4应用说呢?添加一些日志。 – Lutando

+0

你好,我正在尝试同样的事情......你有没有得到一个工作? 它甚至可以工作吗? –

+0

@ JalalEl-Shaer添加了答案。希望能帮助到你。 – Liam

回答

8

好的我得到了这个工作。

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

       } 
      }; 
     } 
+0

对我来说,它没有额外的“signin-oidc”到Uri。 –

+0

谢谢!我昨天失去了很多时间,现在终于有效了! –