@@ -7,32 +7,44 @@ This SDK was created to enable rapid efiicient development using Shopify's API.
77
88## Installation
99
10- ``` json
11- {
12- "require" : {
13- "robby-bugatti/shopify-php-sdk" : " 1.0.0"
14- }
15- }
16- ```
17- or
10+ Easily install this package with composer
1811
1912``` shell
2013composer require robby-bugatti/shopify-php-sdk
2114```
2215
23- then install
24-
25- ``` shell
26- composer install
27- ```
28-
2916Before you can start using this SDK, you have to create a <a href =" https://partners.shopify.com/ " >Shopify Application</a >
3017You can now use the API key and secret to generate access tokens, which can then access a stores data
3118
19+ ### A Note on Strict Execution
20+
21+ When the SDK is run, it defaults to running in a strict environment. This requires that:
22+ A) The HMAC Hash of request parameters matches output generated by your application's secret key
23+ B) Authentication responses contain a 'state' parameter that matches the one placed in the request
24+
25+ Because you can be deploying your application in distributed environments, or be using any number of
26+ storage engines, this SDK will not store these state variables for you. However, it does expose a few
27+ functions for generating and managing them
28+
29+ ``` php
30+ \Shopify\Auth::generateNonce() // Returns a hashed string of <store >.<timestamp >, using API Secret as key
31+ // hash_hmac('sha256', <store >.<timestamp >, \Shopify\Shopify::api_secret());s
32+ ```
33+ This will return a hashed string, composed by concatenating the store name with a timestamp, using the API Secret
34+ as the key.
3235
33- ## Usage / Examples
36+ ``` php
37+ \Shopify\Auth::setNonce( $nonce = NULL )
38+ ```
39+ This will set a nonce in the Auth Object. It will be added to the authorizationUrl, and when required,
40+ compare it to the ?state=<nonce_here> returned by Shopify
3441
35- Essentially, there are 2 ways to initialize this SDK.
42+ ``` php
43+ \Shopify\Auth::checkNonce( $nonce = NULL )
44+ ```
45+ This will return TRUE or FALSE, depending on if the nonce in the URL matches a nonce set through setNonce()
46+ This function is automatically run during accessToken() in strict environments, so you shouldnt need to
47+ call it explicitly
3648
3749### Authentication
3850
@@ -46,14 +58,17 @@ $options = array(
4658 'permissions' => "<permissions your applicaiton requires, comma separated >",
4759 'store' => "myshopify.domain.com"
4860);
49-
5061\Shopify\Shopify::init($options);
5162
63+ // Store this somewhere so we can compare it later
64+ $storageEngine->store($nonce);
65+
5266if(isset($_GET['code']))
5367{
5468 // Redirect to Shopify to start OAuth
5569 header("Location: ".\Shopify\Auth::authorizationUrl());
5670} else {
71+
5772 // We can go ahead and get the access token
5873 echo \Shopify\Auth::accessToken();
5974 // This should return something that looks like this:
@@ -74,6 +89,7 @@ $options = array(
7489
7590You now have access to all the methods the SDK provides!
7691
92+
7793### Reading
7894
7995The SDK uses static methods to fetch data from Shopify
0 commit comments