In Graph api with Client credentials flow /adminconsent api - how to verify a particular tenant?

AD Dev 126 Reputation points
2021-10-29T22:37:57.797+00:00

If we create a multi-tenant app registration, and want to access data for an external tenant via the client credentials flow we can ask their admin to consent using /adminconsent documented here: https://learn.microsoft.com/en-us/graph/auth-v2-service .
After the admin grants consent they are redirected to the redirect_uri, and the tenant_id is provided, however there is no way to guarantee that the tenant_id was not tampered with, furthermore, no way to know which of our users granted consent to a particular tenant. The question is, how can we know if a particular user of our application has access to a particular tenant if we are using the client credentials flow (or in other words, how can we tie one of our users to a particular tenant if they give us permission via client flow)?

I cannot think of a way for this to happen, only way I can think of to do this is to issue a second consent using the delegated oauth flow, and ask the admin to give us permission to call something like /organization or perhaps another api and read the tid embedded in the resulting access token for a successful delegated oauth grant, then we can know a particular of our application has admin privileges in a particular tenant.

Why not just use delegated flow? - in delegated flow the user, even an admin would have to take extra steps for our application to access the resources we need, but the client flow does not have this problem.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,371 Reputation points
    2021-11-01T07:50:22.053+00:00

    Hi, dear @AD Dev

    Your idea is a bit complicated, this is actually a very simple process. When you use the admin consent URL to log in to the administrator of the target tenant, it will still ask the administrator to consent to the MS graph permissions granted to the multi-tenant application in the original tenant. When the administrator of the target tenant consent, the multi-tenant application will be added to the target tenant as an enterprise application and have the permissions granted to it in the original tenant.

    145377-340.png

    So I think you don't need to bind users to the target tenant for collaboration, because you are using the client credential flow and there is no user login involved. Next, you only need to use the client credential flow to obtain a token according to the normal process to access the resources of the target tenant.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.