azure - 如何在本地对 Azure 应用服务进行身份验证?

标签 azure azure-web-app-service azure-api-apps azure-mobile-services

有很多关于如何配置给定 Azure 应用服务实例的身份验证属性的教程:

Api Apps

Expanding App Service Authentication/Authorization

有配置 Azure 服务器端属性的指南:

AAD

FaceBook

Twitter

Google

Microsoft Account

我相信这些都是在位于我们的 Azure 应用服务组件前面的服务器端网关上设置属性。这种方法很好,因为您只需将用户的浏览器定向到 ~/.auth/login/XYZ 即可启动登录流程。

但是,我不知道如何在开发时对其中任何一个进行身份验证,通过本地主机在我的 PC 上本地运行 MVC 应用程序和 API 应用程序。我没有在本地运行的网关。没有端点正在监听 localhost/.auth/login/XYZ。

那么,故事是怎样的呢?你如何在那里进行身份验证?具体来说,您如何进行开发,以便您需要在本地执行的任何操作都可以发布到您的 Web 和 Api 应用程序,并让身份验证体验在 Azure 中的应用程序服务的生态系统中发挥作用?

最佳答案

According to this ,实现此目的的唯一方法是编写一些仅用于开发环境的代码来伪造 IPrincipals,其声明与生产中的 Azure 环境提供的声明等效。

  • Create an appSetting value in web.config that identifies whether the app is in local development mode such as:

    <add key="EnableLocalLogin" value="true" />
  • Define this value in the azure portal application settings as false. This value will overwrite the one configured in the web.config.

  • Create another login option that is only displayed when EnableLocalLogin appSetting is true.
  • The "Login as local developer" button simply calls into an action method which:
    • Checks if the app is in local development mode.
    • If so, constructs an instance of the IPrincipal class with appropriate claims and calls the ASP.Net Identity systems to assign the identity to the current context.

关于azure - 如何在本地对 Azure 应用服务进行身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35953354/

相关文章:

用于将 SQL Azure 备份到 Microsoft Azure Blob 的 Powershell 脚本

azure - 如何为 azure api 应用程序自定义子域?

azure - HSM、应用服务器和数据库之间如何进行交互?

azure - Karate API 测试 - 承载错误 ="invalid_token",error_description ="The audience <number> is invalid"

node.js - 在 Azure 上运行 NodeJS 命令

azure - 使用自定义 URL 访问 Azure WebApp 会产生 "too many redirects"错误

azure - 如何创建 Azure 基于角色的访问控制规则来授权用户调用 azure 函数的能力?

angular - 如何通过本地git将Angular 4应用程序部署到azure web应用程序

api - Azure api 应用程序预配失败

azure - 从 Visual Studio Team Services (VSO) 部署 Azure WebApp