0

Which URL has to be put in the AUTH callback URL, while making the app for Bigcommerce api?

When I click on my draft app its showing nothing.

I am using this url right now:

https://we-apps.com/disstem/public/bigcommerce/auth

https://we-apps.com/disstem/public/bigcommerce : its the path of my file.

Note: I am using laravel framework

My controller file

public function bigcommerce()
{
   $user_id = Auth::id();
   $header =  array(
      "Content-Type" => "application/x-www-form-urlencoded",
   ); 

   $client_id = 'xxxx';
   $client_secret = 'xxxxx';
   $redirect_uri = 'https://w- ap.com/dis/public/bigcommerce';
   $postfields = array(
      "client_id" => $client_id,
      "client_secret" => $client_secret,
      "redirect_uri" => $redirect_uri,
      "grant_type" => "authorization_code",
      "code" =>$_GET['code'],
      "scope" => $_GET['scope'],
      "context" => $_GET['context'],
   );

   $postfields = http_build_query($postfields);
   $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, 'https://login.bigcommerce.com/oauth2/token');
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
         curl_setopt( $ch, CURLOPT_VERBOSE, 0 );
         curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST');
         curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
         curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
         curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
         curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
   $response = curl_exec( $ch );
   $result = json_decode($response);
   print_r($response);

my route file

 Route::get('/bigcommerce', 'IntegrationController@bigcommerce')->name('bigcommerce')->middleware('auth');

my laravel url to run this code is :

 https://w- ap.com/dis/public/bigcommerce

bigcommerce My APP callback url i have given is : same as my laravel url

https://w- ap.com/dis/public/bigcommerce

but its giving the error of 'code' is undefined. . but when i click on install button of the app in bigcommerce its giving me back code,context and scope on and showing it on the bigcommerce but when i run my laravel code its giving me error.

Lia nur fadilah
  • 57
  • 2
  • 13
deep
  • 1
  • 2

1 Answers1

0

The auth callback URL should match whatever route you've defined in your app to respond to the GET request (triggered when your draft app's Install button is clicked within the control panel).

Here's an example from the BC sample PHP app, where '/auth/callback' is the route that's been registered: https://github.com/bigcommerce/hello-world-app-php-silex/blob/master/index.php#L37

In that case, the auth callback URL would be https://myapp.com/auth/callback

If you're using Laravel as your framework, the syntax is a little different, but the concept is the same. Defining a route in your app tells the app to listen for an http request (in this case, a GET) to a specific URL (/auth/callback). When your app detects that a GET request has been sent to /auth/callback, then it will run the callback function you specify to handle the http request.

In the case of installing a BigCommerce app, that callback function should receive the temp auth code, context, and scopes from the GET request and then create a POST back to the BigCommerce auth service to exchange these for a permanent Oauth token (at that point, you store the token and the app shows 'installed' in the control panel). That's exactly what the callback function is doing here.

Edit: It looks like the syntax for handling the GET parameters isn't consistent with what the Laravel docs recommend:

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

You might find the answer here helpful: https://stackoverflow.com/a/34642837/8521556

Karen White
  • 2,123
  • 1
  • 10
  • 13
  • sorry i am quite not understanding this part ' The auth callback URL should match whatever route you've defined in your app'. – deep Oct 31 '18 at 11:15
  • @deep I edited my answer to add a few more details :) Let me know if it helps! – Karen White Oct 31 '18 at 17:48
  • OK, I understood, then can you see my code what a little for better understanding. i am editing my question a little. – deep Nov 01 '18 at 05:58
  • Could you try running var_dump on $postfields to see how the array is being built (and check to make sure the `code` is populating correctly)? – Karen White Nov 01 '18 at 15:10
  • Could you share the full GET request URL with the code, context and scope params? – Karen White Nov 04 '18 at 17:09
  • this is all i have no url to GET the code. this is what i am asking. – deep Nov 09 '18 at 06:55
  • I mean the GET request that BigCommerce sends when your app's Install button is clicked. If you open the Network tab in your browser console, you'll see something like GET `https://w- ap.com/dis/public/bigcommerce?code=qr6h3thvbvag2ffq&scope=store_v2_orders&context=stores/g5cd38`. This would be helpful to make sure that you've registered the correct callback URL in dev tools and that your app is handling the URL parameters properly. – Karen White Nov 09 '18 at 22:37
  • One more suggestion: you might want to try updating the syntax for how you're handling the GET parameters. I'll edit my post to include more details. – Karen White Nov 10 '18 at 13:09