-
Notifications
You must be signed in to change notification settings - Fork 1
/
oauth.php
52 lines (41 loc) · 1.75 KB
/
oauth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
session_start();
require __DIR__.'/vendor/autoload.php';
use phpish\shopify;
require __DIR__.'/conf.php';
# Guard: http://docs.shopify.com/api/authentication/oauth#verification
shopify\is_valid_request_hmac($_GET, SHOPIFY_APP_SHARED_SECRET) or die('Invalid Request! Request or redirect did not come from Shopify');
# Step 2: http://docs.shopify.com/api/authentication/oauth#asking-for-permission
if (!isset($_GET['code']))
{
$permission_url = shopify\authorization_url($_GET['shop'], SHOPIFY_APP_API_KEY, array('read_content', 'write_content', 'read_themes', 'write_themes', 'read_products', 'write_products', 'read_customers', 'write_customers', 'read_orders', 'write_orders', 'read_script_tags', 'write_script_tags', 'read_fulfillments', 'write_fulfillments', 'read_shipping', 'write_shipping'),'https://sendd-shipping.herokuapp.com/');
//$permission_url = $permission_url ."&redirect_uri=https://bulkdelte.herokuapp.com/";
die("<script> window.location.href='$permission_url'</script>");
}
# Step 3: http://docs.shopify.com/api/authentication/oauth#confirming-installation
try
{
# shopify\access_token can throw an exception
$oauth_token = shopify\access_token($_GET['shop'], SHOPIFY_APP_API_KEY, SHOPIFY_APP_SHARED_SECRET, $_GET['code']);
$_SESSION['oauth_token'] = $oauth_token;
$_SESSION['shop'] = $_GET['shop'];
echo 'App Successfully Installed!';
}
catch (shopify\ApiException $e)
{
# HTTP status code was >= 400 or response contained the key 'errors'
echo $e;
print_R($e->getRequest());
print_R($e->getResponse());
}
catch (shopify\CurlException $e)
{
# cURL error
echo $e;
print_R($e->getRequest());
print_R($e->getResponse());
}
?>