C#-AspNet核心身份GetExternalLoginInfoAsync始终为空
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C#-AspNet核心身份GetExternalLoginInfoAsync始终为空,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3010字,纯文字阅读大概需要5分钟。
内容图文
![C#-AspNet核心身份GetExternalLoginInfoAsync始终为空](/upload/InfoBanner/zyjiaocheng/650/23f4d0b1b02641ad8c06910c8642e601.jpg)
我使用IdentityServer4和ASP .NET Core Identity的组合来创建联合的登录页面.我使用的外部提供程序之一是通过Open ID Connect协议的Azure Active Directory.我还为所有数据存储集成了EntityFrameworkCore.
在使用身份验证对初始网站进行脚手架之后,将适当的服务添加到Startup.cs文件中.
services.AddOidcStateDataFormatterCache();
// Some DI registrations
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<MyDbContext>();
services.AddMvc().AddRazorPages(options => /* Some options */);
services.AddIdentityServer(options =>
options.Events.RaiseErrorEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseSuccessEvents = true;
)
.AddConfigurationStore(options => /* Set up DbContext */)
.AddOperationStore(options => /* Set up DbContext */)
.AddAspNetIdentity<MyAppUser>();
services.AddAuthentication().AddOpenIdConnect(options =>
{
// Does not bind itself for mysterious reasons
Configuration.GetSection("OpenIdConect").Bind(options)
});
我决定,如果我在我的appsettings.json文件中进行了大部分身份验证设置,它将看起来更好.
{
"OpenIdConnect": {
"ClientId": "<my_client_id>",
"Authority:" "https://login.microsoft.com/<my_tenant_id>",
"PostLogoutRedirectUri": "http://localhost:5000/MyApp/Account",
"CallbackPath": "/signin-oidc",
"ResponseType": "code id_token",
"Scope": "openid profile email",
"SignInScheme": "idsrv.external",
"AutomaticAuthenticate": "false",
"AutomaticChallenge": "false",
"RequireHttpsMetadata": "true"
}
}
一切正常,我的Open ID Connect登录提供程序自动出现在登录页面上.砸!尝试使用它时,出现一个错误:加载外部登录信息时出错.最终在脚手架剃刀页面上显示
Areas / Identity / Pages / Account / ExternalLogin.cshtml.cs:72包含以下代码:
var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
ErrorMessage = "Error loading external login information.";
return RedirectToPage("./Login", new { ReturnUrl = returnUrl });
}
info始终解析为null.我怀疑这是我的Startup.cs中某个配置问题,或者是没有任何文档值得一提的魔术.
解决方法:
读完我的大脑后,我决定重读the IdentityServer4 documentation about external identity providers.
这引起了我(疲倦)的注意:
Given that this is such a common practise, IdentityServer registers a cookie handler specifically for this external provider workflow. The scheme is represented via the
IdentityServerConstants.ExternalCookieAuthenticationScheme
constant.If you were to use our external cookie handler, then for the SignInScheme [in your OpenIdConnect service setup] you’d assign the value to be the
IdentityServerConstants.ExternalCookieAuthenticationScheme
constant
好吧,我想我没有使用他们的外部cookie处理程序.可以肯定的是,我让ASP.NET Core Identity做到了这一点.我决定在我的appsettings.json中取消这一行:
"SignInScheme": "idsrv.external"
而且,我可以使用Active Directory凭据登录.通过阅读GetExternalLoginInfoAsync的实际源代码,我看到他们正在寻找一个非常特定的cookie,而不是“ idsrc.external”.我需要将其保留为默认值.
内容总结
以上是互联网集市为您收集整理的C#-AspNet核心身份GetExternalLoginInfoAsync始终为空全部内容,希望文章能够帮你解决C#-AspNet核心身份GetExternalLoginInfoAsync始终为空所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。