我如何在此代码中获得 windows 身份?

How am I getting a windows identity in this code?

与此问题相关:

我正在使用 owin 和身份框架来初始化带有身份验证的 IIS 托管 Web 应用程序...

    public static void Configure(IAppBuilder app, IKernel kernel)
    {
        // ensure that owin creates the required UserManager & sign in manager per owin instance
        app.CreatePerOwinContext<ApplicationUserManager>((options, owinContext) => ApplicationUserManager.Create(options, owinContext, kernel));
        app.CreatePerOwinContext<ApplicationSignInManager>((options, owinContext) => ApplicationSignInManager.Create(options, owinContext, kernel));

        GlobalFilters.Filters.Add(new AuthorizeAttribute());
        app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

        app.Use((context, next) =>
        {
            // figure out if the user is in fact authenticated if not use "Guest" as the username here
            var userName = context.Request?.User?.Identity?.Name ?? "Guest";

            //THE QUESTION:
            // Why at this point is context.Request.User a windows user with a username of ""

            return next.Invoke();
        }).UseStageMarker(PipelineStage.PostAuthenticate);
    }

我没有在任何地方使用 windows 身份验证,只使用承载身份验证,并且在服务器上 windows 身份验证在 IIS 中被禁用,所以我如何获得这个 "empty" 身份和我该如何解决这个问题,以便从当前请求中的授权信息中获取基于令牌的身份?

嗯,

Identityframework 似乎在通过身份验证但找不到匹配项时退回到此状态。

我在 header 中有一个基本的身份验证字符串,它正在寻找无法验证的不记名令牌。

我很确定这是一种奇怪的行为,某种身份验证失败/安全异常可能是更好的解决方案。