使用Katana身份验证中间件保护Web API

时间:2013-09-14 19:40:19

标签: asp.net-web-api owin

我的WebAPI部署在带有Owin的Azure上的WorkerRole中。

我现在想尝试身份验证。 (请记住,因为我担任工人角色,所以没有前端。)

我似乎无法找到关于此主题的任何示例或博客文章,并想知道这里是否有人做了什么,并且可以指出一些例子。

我一直在关注Microsoft.Owin.Security。*但我没看到如何在我的owin启动中使用它们的链接。

我把它放在创业公司:

app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.ExternalAuthenticationType);
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = CookieAuthenticationDefaults.ExternalAuthenticationType,
            AuthenticationMode = AuthenticationMode.Active,
            CookieName = CookieAuthenticationDefaults.CookiePrefix + CookieAuthenticationDefaults.ExternalAuthenticationType,
            ExpireTimeSpan = TimeSpan.FromMinutes(5),
        });
        app.UseMicrosoftAccountAuthentication( "hidden", "hidden");

我的nexts步骤是什么,当我完成前端后如何进行身份验证。 javascript或控制台应用程序中显示的示例都可以。

1 个答案:

答案 0 :(得分:2)

Visual Studio 2013 RC附带的SPA模板将是一个很好的起点,可以通过删除所有MVC和ASP.NET相关代码轻松转换为OWIN自主机应用程序。

请查看我的博客Understanding Security Features in the SPA Template for VS2013 RC,以便更好地了解SPA模板中的安全功能。

您最好使用bearer token而不是cookie来保护您的web api。 Cookie会因CSRF攻击而受到攻击。

相关问题