if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['code'])) {
    if (isset($_GET['admin_consent'])) {
        $_SESSION['admin_consent'] = $_GET['admin_consent'];
    }
    if (isset($_GET['code'])) {
        $_SESSION['code'] = $_GET['code'];
    }
    if (isset($_GET['session_state'])) {
        $_SESSION['session_state'] = $_GET['session_state'];
    }
    if (isset($_GET['state'])) {
        $_SESSION['state'] = $_GET['state'];
    }
    // With the authorization code, we can retrieve access tokens and other data.
    try {
        AuthenticationManager::acquireToken();
        header('Location: sendmail.php');
        exit;
    } catch (\RuntimeException $e) {
        echo 'Something went wrong, couldn\'t get tokens: ' . $e->getMessage();
    }
}
// *********************************************************
//
// O365-PHP-Microsoft-Graph-Connect
// https://github.com/OfficeDev/O365-PHP-Microsoft-Graph-Connect
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License: