PHPackages                             codeinternetapplications/shopify-oauth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. codeinternetapplications/shopify-oauth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

codeinternetapplications/shopify-oauth
======================================

Oauth 2.0 authentication for Shopify apps

1.1.6(7y ago)24072MITPHPPHP &gt;=7.0.0

Since Jun 4Pushed 7y agoCompare

[ Source](https://github.com/codeinternetapplications/shopify-oauth)[ Packagist](https://packagist.org/packages/codeinternetapplications/shopify-oauth)[ Docs](https://github.com/codeinternetapplications/shopify-oauth)[ RSS](/packages/codeinternetapplications-shopify-oauth/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (11)Used By (0)

Shopify Oauth connector
=======================

[](#shopify-oauth-connector)

This packages enables you to make an OAuth connection with [Shopify](https://www.shopify.com/).

The package was originally written to use with [Lumen](https://lumen.laravel.com/). But it can also be used in combination with [Laravel](https://www.laravel.com/). Note that since it was made for Lumen the connector is stateless.

Installation
============

[](#installation)

Use composer to install this package into your project

```
composer require codeinternetapplications/shopify-oauth

```

Configuration
-------------

[](#configuration)

We tried to make it as easy as possible. Perform these steps to start:

### Copy config file

[](#copy-config-file)

Copy the `shopify_oauth.php` config file to your config directory and make it available in the `bootstrap/app.php` file.

### Adjust your keys in the config

[](#adjust-your-keys-in-the-config)

Set your `api_key`, `api_secret_key` and `base_url`. Also adjust your `scopes`. You can use the `.env` file for this (see below)

### Make sure your app supports Facades and Eloquent

[](#make-sure-your-app-supports-facades-and-eloquent)

In Lumen you will have to uncomment these lines in `bootstrap/app.php`:

```
// $app->withFacades();

// $app->withEloquent();
```

#### Environment file

[](#environment-file)

Put these variables in your `.env` file:

```
SHOPIFY_APP_BASE_URL=https://url-to-your-app/
SHOPIFY_OAUTH_API_KEY=
SHOPIFY_OAUTH_SECRET_KEY=

```

Also make sure that your `APP_KEY` is defined. Since we encrypt some data in the database Lumen/Laravel needs this key to encrypt it.

### Register the ShopifyOauthServiceProvider

[](#register-the-shopifyoauthserviceprovider)

Register the `ShopifyOauthServiceProvider` in your application.

### Run migrations

[](#run-migrations)

Run the migrations so you get the `con_shops` and `con_shop_access_tokens` table.

```
php artisan migrate

```

Usage of Middleware
-------------------

[](#usage-of-middleware)

Make sure that when you want to use the `online token` you will have to add the Middleware `shopify-oauth-handler`. It is advisable to use these middlewares in your routes:

- shopify-hostname-validation
- shopify-hmac-validation
- shopify-oauth-handler

For example:

```
$router->group([
    'middleware'    => [
        'shopify-hostname-validation',
        'shopify-hmac-validation',
        'shopify-oauth-handler',
    ]
], function() use ($router) {

    // Redirect to Polaris view
    $router->addRoute(['GET','POST','PUT'], '/[{page}]', function () {
        return view('polaris');
    });
});
```

Execute scripts after installation
----------------------------------

[](#execute-scripts-after-installation)

To install webhooks or trigger something right after the installation of the application you will have to implement an event listener into your app.

When the App is installed an event is triggered. You can listen to this event and implement custom actions such as:

- Install webhooks
- Trigger some data imports

### Create listener and listen

[](#create-listener-and-listen)

Open your `bootstrap/app.php` file and make sure that the `EventServiceProvider` is enabled.

Open the `EventServiceProvider.php` file and add these lines:

```
    protected $listen = [
        'CodeInternetApplications\ShopifyOauth\Events\PostShopifyCallbackEvent' => [
            'App\Listeners\PostShopifyCallbackListener',  // assuming that your listener is located at App\Listeners\PostShopifyCallbackListener
        ],
    ];
```

Create a new local listener in your `app/Listeners` folder and add the scripts you want to perform. You can start with this template:

```
