2016-09-22 18 views
10

Tôi có một trang web chạy trên ASP.NET MVC 4.5.2. Tôi có một máy chủ IdentityServer4 chạy nhưng khi tôi cố gắng và xác thực chống lại nó tôi nhận được một:ASP.NET MVC 4.5.2 kết nối với IdentityServer4

invalid_request 

Đối với ASP.NET MVC Lõi các documentation có:

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

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

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

tôi bao gồm các gói NuGet sau trong dự án của tôi Microsoft.Owin.Security.OpenIdConnect. Mã của tôi như sau:

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

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

      ClientId = "mvc", 
     }); 

Làm cách nào để kết nối chính xác với mã này?

+0

làm các bản ghi nói gì về việc áp dụng IdentityServer4? thêm một số đăng nhập. – Lutando

+0

Xin chào, tôi đang cố gắng điều tương tự ... bạn đã bao giờ có được một công việc xung quanh? Tính năng này có hoạt động không? –

+0

@ JalalEl-Shaer đã thêm một câu trả lời. Hy vọng nó giúp. – Liam

Trả lời

8

OK Tôi đã làm việc này.

Bạn cần thêm gói NuGet sau vào giải pháp Microsoft.Owin.Security.OpenIdConnect.

Startup.Auth.cs My chứa

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

     } 

cấu hình khách hàng của tôi trong IdentityServer là:

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

Với tôi nó đã hoạt động mà không cần thêm "signin-oidc" vào Uri. –

+0

Cảm ơn! Tôi đã mất rất nhiều thời gian vào ngày hôm qua và bây giờ nó đã hoạt động! –

Các vấn đề liên quan