Azure 应用程序客户端 ID 存储在前端是否安全?

Are Azure Application Client ID's safe to store in the frontend?

在 Microsoft 网站上,他们提供了多个有关如何使用 msal 对 SPA 中的 Azure AD 用户进行身份验证的示例。在所有这些 examples 中,Application (client) ID 以纯文本形式存储在代码中或简单的 .json 文件中。

我的问题是,鉴于存储在前端的所有内容都被认为是 public,将 Azure (client) ID 之类的应用程序配置简单地存储在 json 文件中是否是一种不好的做法?或者将其存储在 .env 文件中会更好吗?

这些是应用运行所需的详细信息:

AZURE_APP_CLIENT_ID=""
AZURE_APP_AUTHORITY=""
AZURE_APP_REDIRECT_URI=""
AZURE_APP_POST_LOGOUT_REDIRECT_URI=""

API_URI=""
API_AZURE_EXPOSED_SCOPE=""

嗯,OAuth RFC 将其定义为非秘密:https://www.rfc-editor.org/rfc/rfc6749#section-2.2

The client identifier is not a secret; it is exposed to the resource owner and MUST NOT be used alone for client authentication.

无论如何,当用户登录时,客户端 ID 将在 URL 中可见。 放在前端完全没问题

当用户登录时,所有这些内容都在 URL 中可见:

  • Azure AD 租户 ID
  • 应用程序客户端 ID
  • 应用程序请求的范围(可以包括 AAD 中 API 的客户端 ids/app ID URI)
  • 应用重定向 URI