Azure SWA 开发 - 在本地开发期间访问存储

问题描述 投票:0回答:1

我正在开发一个 SWA 应用程序,希望在我的应用程序中使用 API 来访问 Azure 存储。 最终,我更愿意为此使用托管实体。

我使用的是AD认证,但是本地开发时,使用的是模拟器。

本地开发时,如何访问实际的Azure资源?我是否需要直接使用密钥并管理凭证?即使模拟器正在使用中,我也可以利用 azure 登录吗?

如有任何指点,我们将不胜感激。

azure azure-table-storage azure-static-web-app
1个回答
0
投票

我尝试创建一个示例 SWA 应用程序并使用模拟器在本地运行它。遗憾的是,您无法使用模拟器对 Azure 资源进行身份验证,因为模拟器只会模拟存储模拟器中 Azure 存储帐户的类似行为。如果您想使用 Azure 存储帐户进行身份验证,您需要参考步骤此处

我已经参考了这个github存储库中的步骤。

使用

vanilla swa app
:- 在本地运行
storage emulator

 npm install @azure/static-web-apps-cli
 npx swa init
 npx swa start

enter image description here

enter image description here

enter image description here

enter image description here

添加此行以将您的应用程序与 Azure AD 作为从此处

引用的身份提供商连接
[Azure Static Web Apps Emulator - Authentication Portal](http://localhost:4280/.auth/login/aad)

.auth/login/aad

enter image description here

但是,如果您想从存储模拟器 CLI 终端运行 Azure 命令,可以从此 link 下载存储模拟器并运行

az login
命令,如下所示:-

这将像普通的 az cli 命令行工具一样连接到您的 azure 资源。如果您希望静态 Web 应用程序访问 Azure 资源,则需要使用 Azure AD 在应用程序源代码中实施身份验证。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.