使用 AAD B2C 的 MSAL 客户端凭据

MSAL Client Credential with AAD B2C

我想允许 B2C 安全应用程序的用户在决定注册之前进行浏览

为此,我需要在我的应用程序中嵌入一个客户端凭证流

我只能找到处理图形 API 的示例,它是我的 AAD

中保护的 API 的无效令牌

是否有人能够修改下面的示例以指示客户端凭据参数在下面关于 b2clogin 的样子,以便向其传递应用程序 ID、秘密和 return 令牌可用于授权调用 API?

编辑:这就是我现在要传递的内容,以尝试获得我可以使用的令牌

    public static string tenantID = "aadtenant.onmicrosoft.com";
    public static string ClientID = "xxxx-a2e2-40f5-958b-dc39ca2bd413";
    public static string Secret = "zzzzzzzzs_JhPY1HSFEREgRy5Z2rcL";
    public static string redirectURI = "https://mysite.azurewebsites.net/api";
    public static string[] scopes = new string[] { "api://xxxxxx-a2e2-40f5-958b-dc39ca2bd413/.default" };
    public static string url = String.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/token", tenantID);

然而这return是一个失败

Exception AADSTS50059: No tenant-identifying information found in either the request or implied by any provided credentials.

我注意到的一件事是,当我在我的 AAD 租户应用程序中设置 API 访问权限时,仅分配了图形。当我转到我的 APIs 时,我什么也没看到。所以我不确定 AAD 应用程序和 B2C 应用程序究竟是如何相互关联的

另一个编辑:我现在已经从 AAD 应用程序授予 B2C 应用程序权限并创建了一个范围,但我仍然收到错误,这次范围无效

上次我对使用 B2C 的 API 实施客户端凭据身份验证, 我基本上必须向 API 添加第二个身份验证方案。 我在 B2C 租户的底层 Azure AD 中注册了一个应用程序, 在那里注册了一个应用程序权限(appRole), 然后可以将其分配给客户端应用程序(也需要在基础 AAD 租户中注册)。

然后 API 需要能够验证来自 B2C 注册范围的两个访问令牌, 或具有来自 AAD 注册的应用程序权限(角色)。 这些代币的发行人等不同。

坦率地说,这有点痛苦,但这基本上是文档推荐的内容:https://docs.microsoft.com/en-us/azure/active-directory-b2c/application-types#daemonsserver-side-applications

Although client credential flow is not currently supported by Azure AD B2C, you can set up client credential flow using Azure AD. An Azure AD B2C tenant shares some functionality with Azure AD enterprise tenants. The client credential flow is supported using the Azure AD functionality of the Azure AD B2C tenant.

完成所有设置后,您的客户端需要使用 AAD 注册客户端 ID + 密码,范围设置为 api-client-id/.default