有很多关于如何配置给定 Azure 应用服务实例的身份验证属性的教程:
Expanding App Service Authentication/Authorization
有配置 Azure 服务器端属性的指南:
我相信这些都是在位于我们的 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/