how to get access token?

Pablo Peralta 0 Reputation points
2023-11-07T15:49:22.8966667+00:00

When I try to get an access token like this

$client_id = 'TU_CLIENT_ID';
$redirect_uri = 'TU_URL_DE_REDIRECTION';

$auth_url = "https://login.microsoftonline.com/TU_DIRECTORY_ID/oauth2/authorize" . 
            "?client_id=$client_id" .
            "&response_type=code" .
            "&redirect_uri=$redirect_uri" .
            "&response_mode=query" .
            "&resource=https://ads.microsoft.com" .
            "&scope=bingads.manage";
header("Location: $auth_url");

Redirects me to login and shows me the following error

The selected user account does not exist in the "Microsoft Services" tenant, so the application "XXXXXXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXXXXXXXXXXXXXXXX" cannot be accessed from this tenant. To do this, first of all you need to add the account as an external user in the tenant. Use another account.

How do I add the tenant? it is not clear in the documentation.

Microsoft Configuration Manager Application
Microsoft Configuration Manager Application
Microsoft Configuration Manager: An integrated solution for for managing large groups of personal computers and servers.Application: A computer program designed to carry out a specific task other than one relating to the operation of the computer itself, typically to be used by end users.
501 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,056 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,101 Reputation points Microsoft Employee
    2023-11-08T08:24:45.13+00:00

    Hi @Pablo Peralta ,

    Thanks for reaching out.

    I understand you are trying to get the access token and registered the application in the "Microsoft Tenant".

    Since you are connected to the Microsoft Services tenant as a standard user with restricted access, you cannot perform actions such as creating new users, groups, enterprise applications, and so on. To perform administrative actions, you must have administrative access to the tenant.

    For this purpose, you need to create your own tenant rather than using the Microsoft Services (f8cdef31-a31e-4b4a-93e4-5f571e91255a) tenant. When you create a new tenant, you by default become the Global Administrator of the new tenant and have full access to all the options in that tenant.

    To create a new tenant, open in-private/incognito browser window (just to avoid SSO), access https://azure.microsoft.com/en-us/free/ to create a free Azure account.

    User's image

    Once the new account is created, you should be able to see and switch to the new tenant by clicking on the settings icon as highlighted below:

    174999-image.png

    Refer the similar ask: https://learn.microsoft.com/en-us/answers/questions/1377925/issue-while-logging-in-to-azure-entra-portal-aadst

    Hope this will help.

    Thanks,

    Shweta


    Please remember to "Accept Answer" if answer helped you.


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.