azure - 在 Azure 移动应用程序中向经过身份验证的用户添加其他声明

标签 azure authentication azure-mobile-services

我正在学习 Azure 应用服务中的 Azure 移动应用可能性,并且有几个有关身份验证(和授权)的问题。我使用 Azure 移动应用程序 Quickstart了解可用的功能。

第一个问题: 我是否正确理解我无法使用 Microsoft.Azure.Mobile.Server.Login 包实现自定义身份验证,如文章 Work with the .NET backend server SDK for Azure Mobile Apps 的“如何:为应用程序使用自定义身份验证”部分中所述。因为我想使用内置的 Azure 身份验证提供程序(用于 Facebook、Google 等的身份验证)? 在安全性方面,我更喜欢配置和使用内置功能而不是自定义开发;-)

第二个问题: 我目前正在尝试向在我的 Azure 移动应用程序中成功注册和身份验证的用户添加一些自定义声明(例如,根据用户的 SID 从 Azure SQL 数据库读取的角色声明)。 实现这一目标的最佳方法是什么? 我的想法是在 TableController 的 Initialize 方法中添加声明,如下所示,然后使用 [Authorize(Roles = "Test")] 属性检查角色。 有什么理由不这样做吗?

    protected override void Initialize(HttpControllerContext controllerContext)
    {
        base.Initialize(controllerContext);
        myapptestContext context = new myapptestContext();
        DomainManager = new EntityDomainManager<TodoItem>(context, Request);

        var claimsPrincipal = this.User as ClaimsPrincipal;
        ClaimsIdentity ci = new ClaimsIdentity();
        string role = "Test"; // get role from Azure SQL database based on user's SID
        ci.AddClaim(new Claim(ClaimTypes.Role, role));
        claimsPrincipal.AddIdentity(ci);
    }

最佳答案

如果您打算使用内置身份验证提供程序,则无需使用 Microsoft.Azure.Mobile.Server.Login。内置提供商(AAD、Facebook、Google、Twitter、MSA)将为您处理所有详细信息。

就自定义声明而言,我没有任何具体指导。您可以将它放在 Controller 初始化中,或者您可以添加一个注入(inject)它的自定义中间件,甚至是 Global.asax 中的回调。无论哪种方式最适合您和您的应用。

关于azure - 在 Azure 移动应用程序中向经过身份验证的用户添加其他声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36817665/

相关文章:

c - 如何使用 openssl 在 C 代码中进行相互 tls 身份验证?

ruby-on-rails - 设计可确认不能在最新版本中工作

javascript - 将查询参数从 HTML/JS 应用程序传递到 Azure 服务器脚本

c# - 在插入另一个表时创建新表 Azure Sql UWP Apps

c# - 无法验证 Windows Live 帐户 Windows Azure AD

azure - 在Azure数据收集规则中我无法选择源

azure - (400) 通过 ARM 部署 Function App 时出现错误请求

regex - 如何在 Azure Purview 中为数据分类创建列名称模式匹配?

Azure Active Airectory (AAD) 服务到服务身份验证

android - 在 Azure Project 的 Xamarin 表单中使用 Azure 移动服务时找不到“HttpClientHandler.set_AutomaticDecompression”错误