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

How do you authencate to Azure App Services locally?

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

Api Apps

Expanding App Service Authentication/Authorization

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

AAD

FaceBook

Twitter

Google

Microsoft Account

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

即可启动登录流程

但是,我无法弄清楚我应该如何在开发时针对这些中的任何一个进行身份验证,运行 MVC 应用程序和 API 通过本地主机在我的 PC 上本地应用程序。我本地没有网关 运行。没有端点监听 localhost/.auth/login/XYZ.

所以,这是怎么回事?您如何在那里进行身份验证?具体来说,您如何以这样一种方式进行开发,即无论您需要在本地做什么,都可以发布到您的 Web 和 Api 应用程序,并让身份验证体验在应用服务的生态系统中工作蔚蓝?

您需要设置备用登录主机。您没有提及您正在使用的 SDK,但这通常由以下设置:

抱歉,我不知道iOS发展,但是有a loginHost field in that SDK as well

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.