简体   繁体   English

Azure AD B2C 应用程序注册图 API — 说明

[英]Azure AD B2C App Registration Graph API — Clarification

So, I am trying to utilize Graph API with Azure AD B2C.因此,我正在尝试将 Graph API 与 Azure AD B2C 一起使用。 My understanding is that it's not possible to use the client_credentials flow when requesting access tokens.我的理解是,在请求访问令牌时无法使用client_credentials流。 When I try to utilize an access token with client_credentials to get /beta/policies/b2cAuthenticationMethods I receive this error:当我尝试使用带有client_credentials的访问令牌来获取/beta/policies/b2cAuthenticationMethods ,我收到此错误:

{
  "error": {
    "code": "AADB2C",
    "message": "User Authorization: Access is denied.",
    "innerError": {
      "correlationId": "4c00031f-febc-4c1a-9728-701f0c1fda00",
      "date": "2021-01-19T18:51:42",
      "request-id": "77a30adb-5103-40ec-84f3-0626800e976a",
      "client-request-id": "77a30adb-5103-40ec-84f3-0626800e976a"
    }
  }
}

Which is expected since I used the client_credentials flow.这是预期的,因为我使用了 client_credentials 流程。

But, the documentation states the following:但是, 文档说明了以下内容:

Although the OAuth 2.0 client credentials grant flow is not currently directly supported by the Azure AD B2C authentication service, you can set up client credential flow using Azure AD and the Microsoft identity platform /token endpoint for an application in your Azure AD B2C tenant. Although the OAuth 2.0 client credentials grant flow is not currently directly supported by the Azure AD B2C authentication service, you can set up client credential flow using Azure AD and the Microsoft identity platform /token endpoint for an application in your Azure AD B2C tenant. An Azure AD B2C tenant shares some functionality with Azure AD enterprise tenants. Azure AD B2C 租户与 Azure AD 企业租户共享一些功能。

I have gone through the process linked above.我已经完成了上面链接的过程。 However, I am running into one issue and now have questions about this "automated" process:但是,我遇到了一个问题,现在对这个“自动化”过程有疑问:

Question: How do I complete this automated process for requesting and utilizing access tokens with a registered app in B2C if I cannot use the client_credentials flow?问题:如果我无法使用 client_credentials 流,我如何通过 B2C 中的注册应用程序完成请求和使用访问令牌的自动化流程?

I cannot have any user interaction when this application requests an access token.当此应用程序请求访问令牌时,我无法进行任何用户交互。

Do I have to use a different flow?我必须使用不同的流程吗? If so, how do I do it so that things like MFA aren't an issue?如果是这样,我该怎么做才能使诸如 MFA 之类的事情不成问题? I am not using any SDKs, I am just directly querying MGraph using an HttpClient in my application with the Authorization Bearer header passed.我没有使用任何 SDK,我只是在我的应用程序中使用HttpClient直接查询 MGraph,并通过了Authorization Bearer header。

Issue问题

Why am I not able to complete this part of the above linked documentation.为什么我无法完成上述链接文档的这一部分

I am logged in as a global admin for my B2C tenant.我以 B2C 租户的全局管理员身份登录。 I navigate to the Roles and Administrators section我导航到Roles and Administrators部分

在此处输入图像描述

Then, in the Add Assignments popup that appears on the left I start typing the name of my app然后,在左侧出现的Add Assignments弹出窗口中,我开始输入我的应用程序的名称

在此处输入图像描述

and it does not appear, But it is registered: and I can see it in my list of registered applications:它没有出现,但它已注册:我可以在我的注册应用程序列表中看到它:

-

What is the deal here?这里有什么交易?

I have found many other questions similar, and all have led me to the referenced documentation page.我发现了许多其他类似的问题,并且都将我带到了参考文档页面。 But, I still am not quite understanding the correct procedure to automatically get an access token for a registered app in B2C tenants.但是,我仍然不太了解在 B2C 租户中为已注册应用程序自动获取访问令牌的正确程序。

Thanks so much.非常感谢。

Edit编辑

See my answer for both solutions to the problems I had in this post.有关我在这篇文章中遇到的问题的两种解决方案,请参阅我的答案。

Okay, so I managed to find the answer to my issue here .好的,所以我设法在这里找到了我的问题的答案。

Just out of curiosity, I made that ServicePrincipal for my application a Global admin.只是出于好奇,我将我的应用程序的 ServicePrincipal 设为全局管理员。 I used the client_crededentials flow again to the beta/policies/b2cAuthenticationMethodsPolicy and STILL received that above error about User Authorization: Access is dened.我再次使用client_crededentials流到beta/policies/b2cAuthenticationMethodsPolicy并且仍然收到关于用户授权的上述错误:访问被拒绝。 What the heck?有没有搞错? I'm starting to wonder if it's that specific endpoint that's the issue, and not the flow itself.我开始怀疑是否是那个特定的端点才是问题所在,而不是流程本身。 Especially because I can get /beta/users just fine when using the access token from client_credentials flow for my B2C tenant.尤其是因为在为我的 B2C 租户使用来自client_credentials流的访问令牌时,我可以很好地获取/beta/users

Alright, I have found my answers.好吧,我找到了我的答案。

To my issue:对于我的问题:

I found the answer on this thread https://docs.microsoft.com/en-us/answers/questions/229991/azure-ad-b2c-application-won39t-show-up-as-an-opti.html .我在此线程https://docs.microsoft.com/en-us/answers/questions/229991/azure-ad-b2c-application-won39t-show-up-as-an-opti.html上找到了答案。

To my question:对于我的问题:

I opened an issue on the MSFT Docs GitHub page, and someone was able to answer my question there .我在 MSFT Docs GitHub 页面上打开了一个问题,有人能够在那里回答我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM