如何使用 Azure Functions 检查授权

How to check authorization with Azure Functions

我使用 Azure Functions 作为我的 Xamarin Forms 应用程序和我的 ComosDB 之间的中间人 Table。我想我了解身份验证如何使用 Active Directory B2C,但我不清楚授权检查是如何进行的。

我的理解是我可以启用 Active Directory B2C 来验证用户并为他们提供访问令牌。然后,我可以使用令牌作为参数对 Azure 函数进行 http 调用。如何检查令牌对于该用户是否正确。最终,我想保护 Table 中的数据,只提供与该特定用户相关的数据。

至少有两种方法可以在 Azure Functions 中验证令牌:

首先是您可以手动完成:https://github.com/Azure-Samples/ms-identity-dotnet-webapi-azurefunctions/blob/12640a348852696ac0d01e7adfd937900ef8ea40/Function/BootLoader.cs#L73。 这使用 Microsoft.IdentityModel.Protocols.OpenIdConnect 和 System.IdentityModel.Tokens.Jwt 从元数据端点获取配置并验证令牌。 您的主要区别在于 openid 配置 URL,您可以从允许您 运行 B2C 用户流以在 Azure 门户中进行测试的视图中获取。

另一种方法是使用应用服务身份验证:https://cgillum.tech/2016/05/27/app-service-auth-and-azure-ad-b2c/