2016-09-22 36 views
10

Mam stronę internetową działającą na ASP.NET MVC 4.5.2. Mam serwer działa IdentityServer4 ale gdy próbuję i uwierzytelniać przeciwko niemu otrzymuję:ASP.NET MVC 4.5.2 łączenie z IdentityServer4

invalid_request 

dla ASP.NET MVC documentation podstawowej posiada:

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

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

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

jestem tym następujący pakiet Nuget w mój projekt Microsoft.Owin.Security.OpenIdConnect. Mój kod jest następujący:

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

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

      ClientId = "mvc", 
     }); 

Jak prawidłowo połączyć się z nim?

+0

Co dzienniki powiedzieć na temat stosowania IdentityServer4? dodaj trochę logowania. – Lutando

+0

Witaj, próbuję tego samego ... Czy kiedykolwiek miałeś okazję pracować? Czy to działa? –

+0

@ JalalEl-Shaer dodał odpowiedź. Mam nadzieję, że to pomoże. – Liam

Odpowiedz

8

OK Mam to działa.

Musisz dodać następujący pakiet NuGet do swojego rozwiązania Microsoft.Owin.Security.OpenIdConnect.

My Startup.Auth.cs zawiera

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

     } 

Mój config Client w IdentityServer jest:

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

Dla mnie działało bez dodatkowego "signin-oidc" do Uri. –

+0

Dzięki! Wczoraj straciłem dużo czasu i teraz to w końcu działa! –