how to get access token?

Pablo Peralta 0 Reputation points

When I try to get an access token like this

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

$auth_url = "" . 
            "?client_id=$client_id" .
            "&response_type=code" .
            "&redirect_uri=$redirect_uri" .
            "&response_mode=query" .
            "&resource=" .
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.
427 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,075 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 22,881 Reputation points Microsoft Employee

    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 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:


    Refer the similar ask:

    Hope this will help.



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