Documentation
BigCommerce Packages
BigCommerce OAuth

BigCommerce OAuth Laravel

Introduction

Single Click Apps you should have heard this term in BigCommerce Ecosystem, Well This means the app you can quickly install. Awesome, Isn't it? Right

But, Creating a single click app using Laravel as a backend is not that much easy task, Basically it's confusing, Especially Oauth authentication. No need to worry, That why BigCommerce OAuth Laravel packages comes into place.

Quick and easy package which handles all callbacks automatically, With good customisation

Installation

Install package using command line, Using

Command
composer require cronixweb/bigcommerce-oauth-laravel

Now, It's installed.

Migrations

Package comes with database tables which used to store and link BigCommerce Store and User You need to publish migration stubs.

Command (Publish Migrations)
php artisan vendor:publish --tag=bigcommerce-auth-migrations

Once it's published, So refresh database with changes.

Command (Migrate Tables)
php artisan migrate

Configuration

Environment variables

Get All details from https://devtools.bigcommerce.com/my/apps (opens in a new tab)

BigCommerce Devtools

Then setup ENV variables, Which are

BC_CLIENT_ID=BigCommerce-App-Client-ID
BC_SECRET=BigCommerce-App-Secret-ID
BC_REDIRECT_PATH=/

Register Callback Routes

Once Environment variables are set up, You need to have a routes of which you will get callbacks from bigcommerce For that, Add this into web.php file

web.php
use CronixWeb\BigCommerceAuth\BigAuthRoutes;
 
BigAuthRoutes::register();

Callbacks

There are mainly two callbacks, First one is installation and second one is load callback.

  1. domain.com/auth/install
  2. domain.com/auth/load

1). When user installs single click app first time, User will be redirected to our installation url where we are storing all necessary details (you can say it's kinda like registration), And then just logging in that user.

2). Callback is load callback, It's being called when user is opening app anytime after installation, Where getting required details which is required for logging in user.

Laravel Session on iFrame

BigCommerce loads whole single click app in iframe, On other hand our app which is made of laravel needs to activate php session for authentication. For session to work under iframe and make browser accept cookie so that session can work. We need to change things in config/session.php

Add true in SESSION_SECURE_COOKIE default value

Change same_site => lax to none

config/session.php
    'secure' => env('SESSION_SECURE_COOKIE', true),
 
    'same_site' => 'none',

Submit URLs in DevTools

Again you need to open BigCommerce Devtools (opens in a new tab), Put callbacks in your app configurations,

BigCommerce Devtools

BOOM App is ready with BigCommerce Authentication 🥳

NOTE: Don't forget to use https, BigCommerce does things inside iframe which required SSL because main website is using it

Customization

View Files

Again, wanted to take control over view files, Which is used to display default error. then you can run this command to get view files published.

Command
php artisan vendor:publish --tag=bigcommerce-auth-views