【问题标题】:Securing WebAPI with Katana authentication Middleware使用 Katana 身份验证中间件保护 WebAPI
【发布时间】:2013-09-19 06:51:33
【问题描述】:

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

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

我似乎找不到任何关于此主题的示例或博客文章,我想知道这里是否有人做过任何事情并可以指出一些示例。

我一直在查看 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");

我的下一步是什么,当我完成了前端时如何进行身份验证。 javascript 或控制台应用程序中显示的示例即可。

【问题讨论】:

    标签: asp.net-web-api owin


    【解决方案1】:

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

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

    您最好使用不记名令牌而不是 cookie 来保护您的 web api。 Cookie 将受到CSRF 攻击的攻击。

    【讨论】:

    • 看了一眼(本周忙碌的日子),它确实看起来像我想要的。谢谢。
    • 效果很好,我现在开始使用 RTM 版本。但是我的头撞墙试图更新ApplicationOauthProvider。您可以提供更新版本的任何更改吗? (进行了夜间构建并升级了 SPA)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-24
    • 2017-04-29
    • 2018-01-25
    • 2015-01-14
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    相关资源
    最近更新 更多