我需要使用现有的身份服务器对我的 ASP.net MVC 应用程序进行身份验证。它重定向到登录页面并成功验证用户。
但是,问题在于它打开了一个新的浏览器窗口并且它没有点击“if(result.IsError)”块。所以我无法得到认证的结果。请帮助解决这个问题。
相关代码
OidcClientOptions c = new OidcClientOptions();
c.Authority = "http://localhost:5000/";
c.ClientId = "reports";
c.RedirectUri = "https://localhost:44357/AuthCallback";
c.Scope = "openid profile api1 roles";
c.Policy.Discovery.RequireHttps = false;
c.Browser = new SystemBrowser();
c.PostLogoutRedirectUri = "https://localhost:44357/home";
c.ClientSecret = "ClientSecret";
c.LoadProfile = true;
OidcClient cl = new OidcClient(c);
var result = await cl.LoginAsync(new LoginRequest());
if (result.IsError)
{ }
客户端配置
new Client
{
ClientId = "reports",
ClientName = "Reports Client",
AllowedGrantTypes = GrantTypes.Code,
ClientSecrets = { new Secret("ClientSecret".Sha256()) },
RedirectUris = Configuration.GetSection("RedirectUris").Get<List<string>>(),
PostLogoutRedirectUris = Configuration.GetSection("PostLogoutRedirectUris").Get<List<string>>(),
AllowedCorsOrigins = Configuration.GetSection("AllowedCorsOrigins").Get<List<string>>(),
AllowedScopes = { "openid", "profile", "api1", "roles" },
RequireConsent = false,
}