php/googleClientLib/goauth2callback.php.old

    <html>
     <head>
      <title>google oauth2 callback</title>
     </head>
     <body>
      <h2>Google authorization redirect url</h2>
     sending back resource owner authorization to terminal script<br>
<?php
try {
    if (! isset($_GET['state']))
        echo "<br>error state not defined";
    elseif (! isset($_GET['code']))
        echo "<br>error code not defined";
    elseif (! isset($_GET['scope']))
        echo "<br>error scope not defined";
    else {
        file_put_contents('/wkData/pub/oauth2.log', 
          "\nstate=$_GET[state]\ncode=$_GET[code]\nscope=$_GET[scope]\n");
        echo "<h2>written result - continue in terminal script</h2>";
    }
} catch(Throwable $t) {
    echo "<br>>error in " . __FILE__ . '; ' . $t;
}

if (0) {


    // require_once __DIR__.'/vendor/autoload.php';
    define("DTLFMT", 'Y-m-d\tH:i:s');
    session_start();

    /* $client = new Google\Client();
    $client->setAuthConfigFile('client_secrets.json');
    $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php'); 
    $client->addScope(Google\Service\Drive::DRIVE_METADATA_READONLY);
    */
    $o = __FILE__ . ' at '. (new DateTime())->format(DTLFMT) . "\n";
    $o .= '---code=' . ($cd = $_GET['code'] ?? 'undef') . "\n";
    $o .= '---get=' . print_r($_GET, true) . "\n";
    $o .= '---request=' . ($req = print_r($_REQUEST, true)) . "\n";
    $o .= '---server=' . ($srv = print_r($_SERVER, true)) . "\n";
    $o .= '---session=' . print_r($_SESSION, true) . "\n";

    file_put_contents('/wkData/pub/oauth2.log', $o);

    /* 
    xdg-open https://wlkl.ch &
    chromium wlkl.ch


      $auth_url = $client->createAuthUrl();
      header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
    } else {
      $client->authenticate($_GET['code']);
      $_SESSION['access_token'] = $client->getAccessToken();
      $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
      header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
    }

    */

    if (1) {
        echo <<<HTM
        <html>
         <head>
          <title>oauth2callback</title>
         </head>
         <body>
          <h2>Google authorization redirect url</h2>
         code = $cd
         <p>request
         <br/>$req
         <p>server
         <br/>
        HTM ;
        var_dump($_SERVER);
        echo '</body> </html>';
    }
}