Azure Active Directory B2C 是否适用于 Oauth 或 Open ID?

Does Azure Active Directory B2C work with Oauth or Open ID?

我在 Web 应用程序中成功地为用户 management/authentication/login 实施了 Azure Active Directory,遵循以下示例: Azure Sample AAD with Flask

我决定试用 Azure Active Directory B2C,因为它集成了各种社交应用程序。但是,我无法让 flask 应用程序使用 OAuth 2.0 工作,因为 Azure AD B2C 似乎与 OAuth 2.0 不兼容。我发现一些文档指出 Azure AD B2C 需要 Open ID Connect。

请确认 Azure Active Directory B2C 是否需要 Open ID Connect,或者它是否也适用于 OAuth 2.0?

谢谢

根据文档here,Azure AD B2C 同时支持 OpenID Connect 和 OAuth 2.0 协议。

Azure Active Directory (Azure AD) B2C provides identity as a service for your apps by supporting two industry standard protocols: OpenID Connect and OAuth 2.0. The service is standards-compliant, but any two implementations of these protocols can have subtle differences.

Azure AD B2C 支持 OpenID Connect 和 OAuth 2.0,如官方所述reference protocols documentation

为了能够使用 OAuth 2.0 和 Flask 通过 Azure AD B2C 登录用户,您需要调整示例以遵循此示例中使用的 OAuth 2.0 方法:An Android application with Azure AD B2C using OAuth。您需要适应的关键事项:

  • 您需要指定 B2C 授权和令牌端点:https://login.microsoftonline.com/tfp/TENANT_NAME/POLICY_NAME/oauth2/v2.0/authorizeExample from Android sample
  • 您需要添加您的 application/client ID 作为范围。 Example from Android sample
  • 您将无法调用 Graph 的 /me 端点进行令牌验证和获取用户详细信息。您需要验证令牌并自己从中提取声明(最好通过一个好的 JWT 开源库,因为这不是微不足道的,不幸的是,我目前不知道可以推荐什么)。

编辑

我创建了一个 python sample for Azure AD B2C and used python-jose 用于令牌验证和声明检索。看看吧。

值得一提的是,Azure Active Directory B2C (AAD B2C) 通过引入策略来处理用户注册体验,从而支持两者 OpenID Connect and OAuth 2.0 in that it uses these two protocols to exchange information and secure tokens. However, AAD B2C "extends" 这些协议, 登录和一般账户管理。

这是什么意思?首先,这意味着您无法创建自己的 sign-up/sign-in 体验,您只能将用户重定向到正确的策略 (which you to some extent can customize)。您不能为此创建自己的 sign-up/-in UI,并且您只能 styling/branding 为此提供的基于网络的 UI。

因此,为了使用 AAD B2C 身份验证,您可以遵循 this guide, it should be easy enough to adapt to Python. You simply redirect the user to the /authorize endpoint of the AAD B2C and then validate the JWT you receive