Ad

Cannot Get OAuth To Work With Laravel And BigCommerce App

- 1 answer

I am having issues setting up the "One-Click-App" oAuth on Bigcommerce with the BC PHP API library.

The issue at the moment is getting the actual auth token. I've tried various methods and believe it's down to the (Code/Context/Scope) get requests. They return as null every time.

I've tried both:

$request->query('code');
$request->get('code');

On the BC app launch screen I am presented with:

Trying to get property 'access_token' of non-object 

Which of course is because the token is returning null.

Here is my controller in Laravel

namespace App\Http\Controllers;

use \Illuminate\Http\Request;
use Bigcommerce\Api\Client as Bigcommerce;

class BController extends Controller
{
    //
    public function index(Request $request)
    {
      $object = new \stdClass();
      $object->client_id = 'xxxxxxxxxxxxxx';
      $object->client_secret = 'xxxxxxxxxxxxxxxx';
      $object->redirect_uri = 'https://linkto/process_oauth_result';
      $object->code = $request->query('code');
      $object->context = $request->query('context');
      $object->scope = $request->query('scope');
      Bigcommerce::useJson();

      $authTokenResponse = Bigcommerce::getAuthToken($object);

      // configure BC App
      Bigcommerce::configure([
     'client_id' => env('xxxxxxxxxxxxxx'),
     'auth_token' => $authTokenResponse->access_token,
     'store_hash' => 'xxxxxxx'
   ]);

        Bigcommerce::verifyPeer(false);

        return 'Success!';
    }
}
Ad

Answer

Well it turns out that this works fine. I am using Runcloud to manage the app and the click-jacking option was blocking the iframe on the app screen!

Ad
source: stackoverflow.com
Ad