使用 AD B2C 进行守护程序应用程序的 Azure 函数身份验证
Azure Function Authentication using AD B2C for Daemon Applications
我在使用 Azure AD B2C 进行身份验证的高级计划中有一个 Azure Function App 运行。简单 SPA 的用户通过 AD B2C 的 signin 流程获取令牌。 SPA 在 AD B2C 中注册为应用程序,功能应用程序的身份验证配置为使用该应用程序注册:
身份验证/Azure Active Directory/高级
ClientId: <ClientId of the app registration>
发行者Url: https://<ADB2C-Tenant>.b2clogin.com/<ADB2C-Tenant>.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=B2C_1_Sign_In
使用通过 SPA 获得的这些令牌对 Function App 的调用工作正常。
现在,我需要一个守护进程应用程序(目前是函数本身)来访问 Function App,而无需用户执行登录。
为此,我尝试使用共享密钥获取令牌作为客户端凭证:
GET
https://login.microsoftonline.com/<B2C-Tenant-Id>/oauth2/v2.0/token?
grant_type=client_credentials
&client_id=<ClientId of the app registration>
&scope=https://<ADB2C-Tenant>.onmicrosoft.com/<ClientId of the app registration>/.default
&client_secret=<Secret of the app registration>
这成功 returns JWT 令牌,但是使用它来验证对函数应用程序的调用会导致 401: You do not have permission to view this directory or page.
。
我怀疑这是由令牌的“虚假”发行者引起的:https://login.microsoftonline.com/<ADB2C-Tenant>/v2.0
而不是工作 JWT 令牌的发行者:https://<ADB2C-Tenant>.b2clogin.com/<B2C-Tenant-Id>/v2.0/
。后者被函数应用接受,前者不被接受。
我了解 Azure AD B2C 目前不直接支持“OAuth 2.0 客户端凭据授予流程”as described here。但是,该文档描述了一种“解决方法”,这基本上是我的理解,我已经尝试过但没有成功。
我怎样才能让它工作并访问受 Azure AD B2C 保护的 Azure Function 应用程序以及守护程序应用程序?
@Jas Suri 在评论部分提到,我们只能从门户设置一个发行者。您需要使用身份验证库来信任两个颁发者。
FYI Authentication v2 现在支持此功能 - 您可以添加多个身份提供者。
我在使用 Azure AD B2C 进行身份验证的高级计划中有一个 Azure Function App 运行。简单 SPA 的用户通过 AD B2C 的 signin 流程获取令牌。 SPA 在 AD B2C 中注册为应用程序,功能应用程序的身份验证配置为使用该应用程序注册:
身份验证/Azure Active Directory/高级
ClientId: <ClientId of the app registration>
发行者Url: https://<ADB2C-Tenant>.b2clogin.com/<ADB2C-Tenant>.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=B2C_1_Sign_In
使用通过 SPA 获得的这些令牌对 Function App 的调用工作正常。
现在,我需要一个守护进程应用程序(目前是函数本身)来访问 Function App,而无需用户执行登录。
为此,我尝试使用共享密钥获取令牌作为客户端凭证:
GET
https://login.microsoftonline.com/<B2C-Tenant-Id>/oauth2/v2.0/token?
grant_type=client_credentials
&client_id=<ClientId of the app registration>
&scope=https://<ADB2C-Tenant>.onmicrosoft.com/<ClientId of the app registration>/.default
&client_secret=<Secret of the app registration>
这成功 returns JWT 令牌,但是使用它来验证对函数应用程序的调用会导致 401: You do not have permission to view this directory or page.
。
我怀疑这是由令牌的“虚假”发行者引起的:https://login.microsoftonline.com/<ADB2C-Tenant>/v2.0
而不是工作 JWT 令牌的发行者:https://<ADB2C-Tenant>.b2clogin.com/<B2C-Tenant-Id>/v2.0/
。后者被函数应用接受,前者不被接受。
我了解 Azure AD B2C 目前不直接支持“OAuth 2.0 客户端凭据授予流程”as described here。但是,该文档描述了一种“解决方法”,这基本上是我的理解,我已经尝试过但没有成功。
我怎样才能让它工作并访问受 Azure AD B2C 保护的 Azure Function 应用程序以及守护程序应用程序?
@Jas Suri 在评论部分提到,我们只能从门户设置一个发行者。您需要使用身份验证库来信任两个颁发者。
FYI Authentication v2 现在支持此功能 - 您可以添加多个身份提供者。