单页应用程序:移到生产环境Single-page application: Move to production

现在你已了解如何获取用于调用 Web API 的令牌,下面是将应用程序移到生产环境时需要考虑的一些事项。Now that you know how to acquire a token to call web APIs, here are some things to consider when moving your application to production.

启用日志记录Enable logging

为了帮助对调试和身份验证失败进行故障排除,Microsoft 身份验证库提供了内置的日志记录支持。To help in debugging and authentication failure troubleshooting scenarios, the Microsoft Authentication Library provides built-in logging support. 以下文章介绍了如何对每个库进行日志记录:Logging is each library is covered in the following articles:

一些数据收集建议如下:Here are some suggestions for data collection:

  • 用户在有问题时可能会寻求帮助。Users might ask for help when they have problems. 最佳做法是捕获日志并将其临时存储。A best practice is to capture and temporarily store logs. 提供一个供用户上传日志的位置。Provide a location where users can upload the logs. MSAL 提供日志记录扩展来捕获有关身份验证的详细信息。MSAL provides logging extensions to capture detailed information about authentication.

  • 如果遥测可用,请通过 MSAL 启用它,以收集有关用户如何登录应用的数据。If telemetry is available, enable it through MSAL to gather data about how users sign in to your app.

验证你的集成Validate your integration

按照 Microsoft 标识平台集成清单测试你的集成。Test your integration by following the Microsoft identity platform integration checklist.

部署你的应用Deploy your app

请查看部署示例,了解如何使用 Azure 存储和 Azure 应用服务分别部署 SPA 和 Web API 项目。Check out a deployment sample for learning how to deploy your SPA and Web API projects with Azure Storage and Azure App Services, respectively.

代码示例Code samples

这些代码示例演示了单页应用的几个关键操作。These code samples demonstrate several key operations for a single-page app.

后续步骤Next steps

  • JavaScript SPA 教程:深入了解如何使用 MSAL.js 登录用户并获取访问令牌来调用 Microsoft Graph API 。JavaScript SPA tutorial: Deep dive to how to sign in users and get an access token to call the Microsoft Graph API by using MSAL.js.