Asp.net mvc 如何通过Chrome扩展对MVC核心应用进行身份验证?

Asp.net mvc 如何通过Chrome扩展对MVC核心应用进行身份验证?,asp.net-mvc,google-chrome-extension,Asp.net Mvc,Google Chrome Extension,在我的扩展清单中,我有: "permissions": [ "cookies", "https://localhost:5001/" ] 在我的Startup.cs ConfigureServices方法中,我有: services.AddCors(options => { options.AddPolicy(MyAllowSpecificOrigins, builder => { builder.WithOrigins("h

在我的扩展清单中,我有:

"permissions": [
    "cookies",
    "https://localhost:5001/"
]
在我的Startup.cs ConfigureServices方法中,我有:

services.AddCors(options =>
{
    options.AddPolicy(MyAllowSpecificOrigins,
    builder =>
    {
        builder.WithOrigins("https://localhost:5001/",
                            "chrome-extension://mdgfojbohoeindggojmfcphhobepgcbk/");
    });
});
app.UseCors(MyAllowSpecificOrigins);
在Startup.cs Configure方法中,我有:

services.AddCors(options =>
{
    options.AddPolicy(MyAllowSpecificOrigins,
    builder =>
    {
        builder.WithOrigins("https://localhost:5001/",
                            "chrome-extension://mdgfojbohoeindggojmfcphhobepgcbk/");
    });
});
app.UseCors(MyAllowSpecificOrigins);
到目前为止,我所尝试的:

  • 有一个按钮调用
    窗口。打开('Url\u of_signin\u page')
    ,然后在用户登录后重定向回原始页面。这将设置身份验证cookie,当我浏览到需要手动身份验证的端点时,它会工作。但是,
    XMLHttpRequest
    调用不会发送cookie
  • 使用AJAX获取signin表单的HTML,并将其作为div添加到扩展正在运行的当前页面。这里的问题是MVC表单标记帮助程序在表单操作属性中忽略了主机,并且由于它所在的页面不再与应用程序位于同一个域中,因此它无法工作。如果我指定表单操作而不是使用标记助手,那么防伪令牌验证将失败,即使我已将
    @Html.AntiForgeryToken()
    显式添加到登录表单中
  • 最终,我希望用户能够登录到MVC核心应用程序,并让扩展能够向该MVC核心应用程序发出经过身份验证的请求。这可能吗?如果可能,怎么可能

    编辑以添加:我正在XmlHttpRequest上设置withCredentials=true