gpt4 book ai didi

asp.net-mvc-5 - ASP.NET MVC 4.5.2 连接到 IdentityServer4

转载 作者:行者123 更新时间:2023-12-01 22:56:36 25 4
gpt4 key购买 nike

我有一个在 ASP.NET MVC 4.5.2 上运行的网站。我有一个 IdentityServer4 服务器正在运行,但是当我尝试对其进行身份验证时,我得到一个:

invalid_request

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

我在我的项目 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"},

}
};
}

关于asp.net-mvc-5 - ASP.NET MVC 4.5.2 连接到 IdentityServer4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39642715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com