Asp.net-Mvc-5
ASP.NET MVC 4.5.2 連接到 IdentityServer4
我有一個在 ASP.NET MVC 4.5.2 上執行的網站。我有一個 IdentityServer4 伺服器正在執行,但是當我嘗試對其進行身份驗證時,我得到:
invalid_request對於 ASP.NET Core MVC,文件有:
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", });如何正確連接到它?
好的,我得到了這個工作。
您需要將以下 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"}, } }; }