azure = $azure; $this->clientRegistry = $clientRegistry; $this->machineTokenStorage = $machineTokenStorage; } protected function configure() { } protected function execute(InputInterface $input, OutputInterface $output) { $this->azure->scope = ['https://graph.microsoft.com/.default']; $authorizationUrl = explode('?', $this->azure->getAuthorizationUrl(['prompt' => 'consent'])); // replace the first part by the admin consent authorization url $authorizationUrl[0] = strtr('https://login.microsoftonline.com/{tenant}/adminconsent', ['{tenant}' => $this->azure->tenant]); $output->writeln('Go to the url'); $output->writeln(implode('?', $authorizationUrl)); $output->writeln('Authenticate as admin, and copy-paste the url you will reach'); // not necessary ? $helper = $this->getHelper('question'); $question = new Question('Paste here the return url after you completed the admin consent'); $returnUrl = $helper->ask($input, $output, $question); $keyValues = explode('&', parse_url($returnUrl, PHP_URL_QUERY)); $params = []; foreach ($keyValues as $str) { $strs = explode('=', $str); $params[$strs[0]] = $strs[1]; } dump($params); $token = $this->azure->getAccessToken('client_credentials', [ 'scope' => $this->azure->scope, ]); $this->machineTokenStorage->storeToken($token); $output->writeln('machine access token acquired and saved!'); return 0; } }