All Projects → pizdata → oauth2-shopify-php

pizdata / oauth2-shopify-php

Licence: MIT license
Shopify Provider for the OAuth 2.0 Client

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to oauth2-shopify-php

shopapp-shopify-ios
A Shopify provider for a ShopApp for iOS application
Stars: ✭ 49 (+250%)
Mutual labels:  shopify, shopify-api
shopify-graphql-elixir
Elixir client for the Shopify GraphQL Admin API
Stars: ✭ 18 (+28.57%)
Mutual labels:  shopify, shopify-api
shopify-next.js-tailwind
Learn the Shopify + Next.js + Tailwind CSS Stack! SWR, Hydrogen, + more
Stars: ✭ 227 (+1521.43%)
Mutual labels:  shopify, shopify-api
shopify-app-starter-kit
Shopify app starter kit written in Ruby on Rails w/ appropriate tools to get your Shopify app up and running quickly 🚀
Stars: ✭ 42 (+200%)
Mutual labels:  shopify, shopify-api
mechanic-tasks
Public task repository for Mechanic (https://mechanic.dev)
Stars: ✭ 42 (+200%)
Mutual labels:  shopify, shopify-api
shopify-development-resources
A List of resources for Shopify development
Stars: ✭ 56 (+300%)
Mutual labels:  shopify, shopify-api
shopify-node-react-app
Shopify paid app in Node.js & React.js that connects to a store and lets merchants select products to automatically discount them in the Shopify admin interface.
Stars: ✭ 29 (+107.14%)
Mutual labels:  shopify, shopify-api
shopify-node-express-app
Simple Shopify app with Express and Node.js that connects to a Shopify store via OAuth.
Stars: ✭ 20 (+42.86%)
Mutual labels:  shopify, shopify-api
next-shopify-starter
Nextjs + Tailwind CSS + Shopify Starter
Stars: ✭ 385 (+2650%)
Mutual labels:  shopify, shopify-api
bold-shopify-toolkit
A Symfony Based Shopify api wrapper
Stars: ✭ 24 (+71.43%)
Mutual labels:  shopify, shopify-api
monitor
Community restock monitor template
Stars: ✭ 78 (+457.14%)
Mutual labels:  shopify
dry
Dry is a new template engine and language, and is a superset of Shopify's Liquid, with first-class support for advanced inheritance features, and more. From the creators of Enquirer, Assemble, Remarkable, and Micromatch.
Stars: ✭ 66 (+371.43%)
Mutual labels:  shopify
shopify
Vue Storefront 2 integration for Shopify
Stars: ✭ 109 (+678.57%)
Mutual labels:  shopify
shopify-wishlist
💙 A set of files used to implement a simple customer wishlist on a Shopify store
Stars: ✭ 115 (+721.43%)
Mutual labels:  shopify
richer
jquery free ajax cart for shopify
Stars: ✭ 35 (+150%)
Mutual labels:  shopify
nextjs-shopify
This repository contains the app without webhook for the Build a Shopify app with Node and React tutorial.
Stars: ✭ 56 (+300%)
Mutual labels:  shopify
polaris-vue
Polaris Vue by HulkApps is a component library for Vue.js based on Shopify Polaris style guide.
Stars: ✭ 39 (+178.57%)
Mutual labels:  shopify
shopify-node-app-starter
🚀🚀 A Shopify embedded app starter template, written in TypeScript with session storage, app context and examples for basic functionalities.
Stars: ✭ 99 (+607.14%)
Mutual labels:  shopify
hooked
Microservice for communicating between Contentful and Shopify
Stars: ✭ 17 (+21.43%)
Mutual labels:  shopify
gulp-shopify-theme
Shopify theme synchronisation during development
Stars: ✭ 26 (+85.71%)
Mutual labels:  shopify

Shopify OAuth 2.0 Client Provider

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Shopify OAuth 2.0 Client Provider.

Install

Via Composer

$ composer require pizdata/oauth2-shopify

Usage

$provider = new Pizdata\OAuth2\Client\Provider\Shopify([
    'clientId'                => '{shopify-client-id}',    // The client ID assigned to you by the Shopify
    'clientSecret'            => '{shopify-client-secret}',   // The client password assigned to you by the Shopify
    'redirectUri'             => 'http://localhost/callback', // The redirect URI assigned to you
    'shop'                    => 'pizdata.myshopify.com', // The Shop name
]);

// If we don't have an authorization code then get one
if (!isset($_GET['code'])) {

    // Setting up scope
    $options = [
        'scope' => [
            'read_content', 'write_content',
            'read_themes', 'write_themes',
            'read_products', 'write_products',
            'read_customers', 'write_customers',
            'read_orders', 'write_orders',
            'read_draft_orders', 'write_draft_orders',
            'read_script_tags', 'write_script_tags',
            'read_fulfillments', 'write_fulfillments',
            'read_shipping', 'write_shipping',
            'read_analytics',
        ]
    ];
    // Fetch the authorization URL from the provider; this returns the
    // urlAuthorize option and generates and applies any necessary parameters
    // (e.g. state).
    $authorizationUrl = $provider->getAuthorizationUrl($options);

    // Get the state generated for you and store it to the session.
    $_SESSION['oauth2state'] = $provider->getState();

    // Redirect the user to the authorization URL.
    header('Location: ' . $authorizationUrl);
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) {

    if (isset($_SESSION['oauth2state'])) {
        unset($_SESSION['oauth2state']);
    }
    
    exit('Invalid state');

} else {

    try {
        // Try to get an access token using the authorization code grant.
        $accessToken = $provider->getAccessToken('authorization_code', [
            'code' => $_GET['code']
        ]);

        $store = $provider->getResourceOwner($accessToken);

        // Access to Store base information
        echo $store->getName();
        echo $store->getEmail();
        echo $store->getDomain();

        // Use this to interact with an API on the users behalf
        echo $token->getToken();

    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
        // Failed to get the access token or user details.
        exit($e->getMessage());

    }
}

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].