Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Capturing the access code using server auth #34

Open
smithyco opened this issue Mar 22, 2016 · 1 comment
Open

Capturing the access code using server auth #34

smithyco opened this issue Mar 22, 2016 · 1 comment

Comments

@smithyco
Copy link

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.

@hassankhan
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants