2017 © Pedro Peláez
 

library shopify-app-auth-laravel

Shopify OAuth App for Laravel 5.x

image

culturekings/shopify-app-auth-laravel

Shopify OAuth App for Laravel 5.x

  • Thursday, June 29, 2017
  • by jared-fraser
  • Repository
  • 9 Watchers
  • 9 Stars
  • 5,458 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 2 Open issues
  • 27 Versions
  • 3 % Grown

The README.md

shopify-app-auth-laravel

Laravel Auth Boilerplate for Shopify App, (*1)

Installation

Install

composer require culturekings/shopify-app-auth-laravel, (*2)

Add to Providers

Add to Providers in config/app.php CultureKings\ShopifyAuth\ShopifyAuthServiceProvider::class, (*3)

Publish

php artisan vendor:publish, (*4)

Setup Views

Install Success page

In your resources/views folder, create your folder and install-sucess.blade.php file, and then within shopify-auth.app_name, set your view_install_success_path value to whatever it is (see below in configure app for example)., (*5)

Auth Middleware

Set the middleware on routes - ensure that ShopifyAuthCheck if sitting around the routes. Web too, but I think that is standard in the web.php file. Also note that when creating routes, the appname must be second in the url route e.g. apps/app_name/create., (*6)

Route::group(
    [
        'prefix' => 'shopify-apps',
        'namespace' => 'ShopifyApps',
        'middleware' => 'CultureKings\ShopifyAuth\Http\Middleware\ShopifyAuthCheck'
    ],
    function () {
        Route::get('appname', 'AppnameController@getDashboard');
    }
);

Configure App in config

Once published, set up your app., (*7)

You can see below that everything is setup under "appname" and then app_name is used from then on., (*8)

In the routes, you see that appName is passed as a variable in the auth url, so this is very important that url is the same as the array key of "appname"., (*9)

You can change this to be whatever you like so you can run multiple apps through a single auth flow., (*10)

'appname' => [
    'name' => 'app_name', // checked in db, so shouldn't change after launch
    'price' => 0.00,
    'redirect_url' => '/shopify-auth/app_name/auth/callback', // relative uri
    'success_url' => '/shopify-auth/app_name/install/success',
    'dashboard_url' => '/apps/app_name/dashboard',
    'scope' => [
        "write_products",
        "write_script_tags"
    ],
    'view_folder_path' => 'shopify-apps.app_name',
    'view_install_success_path' => 'shopify-apps.app_name.install-success',
    'key' => env("SHOPIFY_APPNAME_APIKEY"),
    'secret' => env("SHOPIFY_APPNAME_SECRET"),
],

Usage

All shopify calls should be made through a service and make a call similar to below:, (*11)

// $appName comes from url passed into method as param (look at middleware)
$shopifyAppConfig = config('shopify-auth.'.$appName);

/ call shopify api
$this->shopify
    ->setKey($shopifyAppConfig['key'])
    ->setSecret($shopifyAppConfig['secret'])
    ->setShopUrl($shopUrl)
    ->setAccessToken($accessToken)
    ->post('admin/script_tags.json', $scriptTags);

Authenticate Shop App

Navigate to: http://exampledomain.dev/shopify-auth/app_name/install?shop=shopifydomain.myshopify.com, (*12)

It will then redirect you to your shops auth process to start, (*13)

Common Controller Setup

I'd generally use this as the construct:, (*14)

public function __construct(ShopifyApi $shopify, Request $request, ShopifyAuthService $shopifyAuthService)
{
     $this->shopify = $shopify;
     $this->shopifySession = $request->session()->get('shopifyapp');
     $this->shopifyAuthService = $shopifyAuthService;
 }

Then set up a method:, (*15)

public function getDashboard()
{
    $shopUrl = $this->shopifySession['shop_url'];
    $appName = $this->shopifySession['app_name'];

    // find user, then get countdowns based on that
    $user = ShopifyUser::where([
        'shop_url' => $shopUrl,
        'app_name' => $appName,
    ])->first();

    $appConfig = config('shopify-auth.' . $appName);

    $this->checkExistsAndCreateScriptTag($shopUrl, $user->access_token, $user, $appName);

    return view('app_name.dashboard')->with([
        'app_key' => config($appConfig['key']),
    ]);
}

The Versions

29/06 2017

dev-master

9999999-dev

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

29/06 2017

3.4

3.4.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

15/06 2017

v3.3

3.3.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/06 2017

v3.2

3.2.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

08/06 2017

v3.1

3.1.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

08/06 2017

v3.0

3.0.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

08/06 2017

v2.6

2.6.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

08/06 2017

v2.5

2.5.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

08/06 2017

v2.4

2.4.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

08/06 2017

v2.3

2.3.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

07/06 2017

v2.2

2.2.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

06/06 2017

v2.1

2.1.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

25/05 2017

v2.0

2.0.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

23/05 2017

v1.6

1.6.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

18/05 2017

v1.5

1.5.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

18/05 2017

v1.4

1.4.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

17/05 2017

v1.3

1.3.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/05 2017

v1.2

1.2.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/05 2017

v1.1

1.1.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/05 2017

v1.0

1.0.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/05 2017

v0.7

0.7.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/05 2017

v0.6

0.6.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/05 2017

v0.5

0.5.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/05 2017

v0.4

0.4.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/05 2017

v0.3

0.3.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/05 2017

v0.2

0.2.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires

 

09/05 2017

v0.1

0.1.0.0

Shopify OAuth App for Laravel 5.x

  Sources   Download

MIT

The Requires