_signInManager.GetExternalLoginInfoAsync() 始终返回带有打开 ID 的 null 到 azure 广告

2023-11-21

为什么signinmanager getexternallogininfoasync 方法总是返回null?

我正在将 VS2015 与默认的 asp.net core(不是框架)项目一起使用,用于具有个人用户帐户的 MVC(这是一个要求)。使用第三方登录的目的是为了让用户自行注册。基于角色的授权将由 asp.net 身份使用通过 Azure AD 注册提供的身份进行处理。

如果以下对管理器登录的解释不正确,请纠正我。此方法应提供有关外部登录的详细信息,并返回一个 ClaimsPrincipal 对象,其中包含身份提供者由用户提供的声明。

我已使用以下指南在 Startup.cs 中设置 OpenIdConnectAuthentication(下面的类部分)

https://azure.microsoft.com/en-us/documentation/samples/active-directory-dotnet-webapp-openidconnect/

当我启动外部登录提供程序时,它会将我定向到组织登录页面并成功。

但是,signinmanager 方法应填充的变量信息为空

如果我在回调类中放置一个断点,则会填充 User 并且 IsAuthenticated 变量为 true。

我可以驱动允许用户自己在应用程序中注册的功能,但是,这是我第一次尝试实现第三方登录,我想了解我现在做错了什么。

启动.cs

  public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddApplicationInsightsTelemetry(Configuration);

        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();
        // Add Authentication services.
        services.AddAuthentication(sharedOptions => {
            sharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;

        });
        //services.AddDistributedMemoryCache();
        //services.AddSession();
        services.AddMvc();

        // Add application services.
        services.AddTransient<IEmailSender, AuthMessageSender>();
        services.AddTransient<ISmsSender, AuthMessageSender>();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        app.UseApplicationInsightsRequestTelemetry();

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
            app.UseBrowserLink();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseApplicationInsightsExceptionTelemetry();

        app.UseStaticFiles();

        app.UseIdentity();

        // Configure the OWIN pipeline to use cookie auth.
        app.UseCookieAuthentication( new CookieAuthenticationOptions());



        //Add external authentication middleware below.To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
        app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
        {

            SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme,
            CallbackPath = "/signin-oidc",
            ClientId = Configuration["AzureAD:ClientId"],
            Authority = String.Format(Configuration["AzureAd:AadInstance"], Configuration["AzureAd:Tenant"]),
            ResponseType = OpenIdConnectResponseType.IdToken,
            PostLogoutRedirectUri = Configuration["AzureAd:PostLogoutRedirectUri"],
            Events = new OpenIdConnectEvents
            {
                //OnRemoteFailure = OnAuthenticationFailed,
            }
        });

        //app.UseSession();
        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

外部登录

        public IActionResult ExternalLogin(string provider, string returnUrl = null)
    {

        // Request a redirect to the external login provider.
        var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });
        var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
        return Challenge(properties, provider);
    }

enter image description here


过去曾多次报告此方法产生空值的问题。对于任何开箱即用的受支持的身份验证方法都不会发生这种情况。至少在将 OAuth 与 azure AD 一起使用并遵循帖子中提供的方法时,这是一个问题。但是,有一种解决方法仍然允许使用默认项目类型。只需将生成ExternalLoginInfo 变量(info) 的方法替换为使用用户原则构建的您自己的ExternalLoginInfo 类即可。

 ExternalLoginInfo info = new ExternalLoginInfo(User,
            "Microsoft",
            User.Claims.Where(x=>x.Type== "http://schemas.microsoft.com/identity/claims/objectidentifier").FirstOrDefault().Value.ToString(),
           "Microsoft" );

ASP.NET MVC 5(VS2013 最终版):使用 OWIN 登录 Facebook 失败(loginInfo 为 null)

MVC 5 Owin Facebook Auth 导致空引用异常

http://blogs.msdn.com/b/webdev/archive/2013/10/16/get-more-information-from-social-providers-used-in-the-vs-2013-project-templates.aspx

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

_signInManager.GetExternalLoginInfoAsync() 始终返回带有打开 ID 的 null 到 azure 广告 的相关文章

随机推荐

  • 为listview设置长按监听器

    我有以下代码 public class MainActivity extends ListActivity protected void onCreate Bundle savedInstanceState super onCreate s
  • JDK8 LocalDate.toEpochDay 性能奇怪下降

    我很好奇我们是否最终能使用 JDK8 获得一个快速的日期时间库 几乎所有LocalDate计算使用toEpochDay所以我看了看source大量的部门和分支机构让我很好奇我是否可以做得更好 我消除了一些分支和除一个分支之外的所有分支 但是
  • 如何告诉 Gradle 使用特定的 JDK 版本?

    我不知道如何让它发挥作用 设想 我有一个用 gradle 构建的应用程序 该应用程序使用JavaFX 我想要的是 使用一个变量 每个开发人员机器定义 该变量指向 JDK 的安装 该 JDK 将用于构建整个应用程序 测试 我想过拥有gradl
  • 比较 SQL Server 2005 中 DateTime 数据类型的时间部分

    如何在 SQL Server 2005 中仅比较 DateTime 数据类型的时间部分 例如 我想获取 MyDateField 在特定时间之后的所有记录 下面的示例是一个非常长且可能不快的方法 我想要 MyDateField 大于 12 3
  • 是否可以使用正则表达式在 MySQL 中强制执行数据检查

    假设我有一个名为电话号码的属性 并且我想对该字段的条目强制执行一定的有效性 我可以使用正则表达式来实现此目的 因为正则表达式在定义约束方面非常灵活 是的你可以 MySQL 支持正则表达式 http dev mysql com doc ref
  • iPhone 上的大多数游戏都是用 OpenGL ES 完成的吗?

    我只是想知道 iPhone 上的大多数游戏是否都是在 OpenGL ES 中完成的 而不是使用 Quartz 和 Core Animation Quartz 和 Core Animation 主要用于创建流畅的界面吗 或者 在游戏中是否存在
  • 如何从 .exe 文件中删除用 Python 编写的 .exe 文件?

    我正在尝试创建一个脚本 将 github 存储库克隆到当前目录中 然后删除调用它的脚本 该脚本是用Python 3 7 4编写的 并编译成 exe 我尝试过使用os remove sys argv 0 它在编译之前有效 但不适用于我的最终应
  • UIDocumentInteractionController 退出时崩溃

    我的主菜单上有一个常规的 UIButton 当前启动了一个 UIViewController 对应的 m文件内容如下 id initWithNibName NSString nibNameOrNil bundle NSBundle nibB
  • 在同一个 C++ 项目中链接两个不同版本的 protobuf 库

    我可以在同一个 C 项目中使用 protobuf 2 6 和 3 0 库并将它们链接在一起吗 您不能将两个不同版本的 libprotobuf 链接到同一个程序中 在某些操作系统上可能可行 但在 Linux 上肯定行不通 因为 Linux 上
  • 如何在 nunjucks 中定义全局变量?

    Using nunjucks 如何定义一些应始终在所有模板中可用的全局变量 理想情况下 它们将在环境或配置选项中的某个位置指定 并且不必在每次调用时合并到上下文字典中nunjucksEnvironment render 这可能对某人也有帮助
  • 如何在您的网站上显示 WordPress RSS feed?

    您好 我有一个网站和一个博客 我想在我的网站上显示我的自托管 WordPress 博客 我只想在我的网站上显示 3 个帖子 我想每次重新加载网站时自动检查是否有新帖子 以便仅显示最近的三个帖子 我想显示我的 WordPress 博客文章的完
  • 为什么axios get方法请求发送两次?

    I run the axios get method to call php script but request send twice how to solve this problem myfunction axios get http
  • 为什么 C# 时分号无法放置在 OracleCommand 的 CommandText 中

    Why 分号 无法放入命令文本OracleCommand 的时候C 就像下面这样 string sql select from table1 OracleCommand oc new OracleCommand sql con oc Com
  • 当 SendMessage 和 Perform 需要 NativeUInt 时,我应该如何将负值传递给它们?

    假设你有这样的代码 Result X ACustomMemo Perform EM LINEFROMCHAR 1 0 Windows API 声称 1 是一个有效值 使其返回活动行 然而 Delphi 将此定义为 NaiveUInt 并且如
  • Java异常处理的良好实践[关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心以获得指导 我对 Java 中的异常处
  • 云代码 Parse.User.current() 返回 null

    当我在 Cloud Code 中使用此函数时Parse User current return null 我在用着parseExpressCookieSession用于登录 有什么建议吗 var express require expres
  • 3d 整数坐标的哈希函数

    拥有 3D 统一网格 为了节省大型模型中的内存 不需要保存空单元格 不与任何对象重叠的单元格 为此 我在 C 中使用字典 尽管性能已经下降 但这仍然比创建 3D 网格时出现异常要好 现在我的问题是找到一个快速哈希函数 将网格的 3d 整数坐
  • R 闪亮的日期滑块动画(按月)(当前按天)

    我对 R 比较满意 对 Shiny 则不太满意 尽管这不是我的第一个 Shiny 应用程序 我有一个数据框 其中包含经 纬度以及每个新客户进入系统的日期 时间 我还根据 startDate 变量创建了其他变量 例如年 月 周 年月 ym 和
  • Windows Python 版本和 VC++ 可再发行版本

    有人可以帮助填写此表 或链接到参考 以识别每个 Python 版本在 Windows 上构建的 VC Redistributable 版本 Windows Python 版本 动态链接库名称 VC 可再发行 链接到安装程序 2 4 msvc
  • _signInManager.GetExternalLoginInfoAsync() 始终返回带有打开 ID 的 null 到 azure 广告

    为什么signinmanager getexternallogininfoasync 方法总是返回null 我正在将 VS2015 与默认的 asp net core 不是框架 项目一起使用 用于具有个人用户帐户的 MVC 这是一个要求 使