ASP.NET MVC 4.5.2 连接到 IdentityServer4 [英] ASP.NET MVC 4.5.2 connecting to IdentityServer4
问题描述
我有一个在 ASP.NET MVC 4.5.2 上运行的网站.我有一个 IdentityServer4 服务器正在运行,但是当我尝试对其进行身份验证时,我得到一个:
I have a website running on ASP.NET MVC 4.5.2. I have an IdentityServer4 server running but when I try and authenticate against it I get an:
invalid_request
对于 ASP.NET Core MVC,文档有:>
For ASP.NET Core MVC the documentation has:
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 包.我的代码如下:
I am including the following NuGet package in my project Microsoft.Owin.Security.OpenIdConnect. My code is as follows:
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.
You need to add the following NuGet package to your solution 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 中的客户端配置是:
My Client config in IdentityServer is:
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"},
}
};
}
这篇关于ASP.NET MVC 4.5.2 连接到 IdentityServer4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!