larabros/elogram

Capturing the access code using server auth

smithyco opened this issue · 1 comments

I'm trying to write a script that will call the API from the command line using the Artisan CLI.

Below is the test code from the Quickstart:

// Start the session
session_start();

// If we don't have an authorization code then get one
if (!isset($_GET['code'])) {
    header('Location: ' . $client->getLoginUrl());
    exit;
} else {
    $token = $client->getAccessToken($_GET['code']);
    echo json_encode($token); // Save this for future use
}

// You can now make requests to the API
$client->users()->search('skrawg');

How can I get the code from the returned URL without having to visit redirect URI?
If I visit that path in the browser, and retrieve the code manually and then try to set the access token with $token = $client->getAccessToken($manualCode), it throws an error because there's no state query parameter to verify CSRF.

Trying to retrieve an access token via the command-line is not supported. This package specifically forces you to do the authorization redirects.

I would retrieve an access token and save it somewhere (database, .env) and then use that in my CLI script.