asp.net-mvc – 需要使用Web应用程序和Web API进行双重身份验证吗?

我坚持如何解决以下问题.
我将首先描述我的应用在一般情况下的外观.

[ASP MVC(Angular App)]

>使用Owin cookie

[WEB API 2]

>使用Oauth Token Bearer

这种情况正在发生:
用户访问应用程序并使用位于ASP MVC应用程序中的登录表单进行身份验证并生成cookie.

现在我决定使用AngularJs添加一些使我使用$resources和Web API 2的功能.但是,这些功能仅在用户获得授权时才可用.

问题所在:现在我必须为Web Api 2的每个请求使用一个令牌来访问控制器中的不同方法.这意味着我必须再次登录用户,但这次是通过AngularJs.使用/ token路由.

我该怎么做?
我应该带cookie,检查其中的凭据并将其作为身份验证请求发送?
我可以在表单身份验证中以相同的方法在Asp MVC应用程序中执行某些操作吗?

请帮帮我,这给了我很多开销.在30分钟内从一个简单的应用程序走到这个.甚至无法理解身份验证中的所有内容.

问候!

解决方法

我的WebAPI支持令牌和cookie身份验证.

在启动过程中,我注册了如下身份验证:

private void ConfigureAuth(IAppBuilder app)
{
    //Token 
    app.USEOAuthBearerAuthentication(new OAuthBearerAuthenticationoptions
    {
    });

    // Enable the application to use a cookie to store information for the signed in user
    app.UseCookieAuthentication(new CookieAuthenticationoptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,LoginPath = new PathString("/Account/Login"),Provider = new CookieAuthenticationProvider
        {
            OnApplyRedirect = ctx =>
            {
                // this is to ensure that a 401 response is sent if the
                // user is not authenticated,rather than redirecting to
                // a logon page.
            }
        },CookieDomain = ".example.com" //might not need to set this
    });
}

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....