phpish / shopify_app-skeleton

Skeleton Shopify App project using phpish/shopify
94 stars 41 forks source link

Not getting installed app #12

Open subhanahmed047 opened 8 years ago

subhanahmed047 commented 8 years ago

but i'm getting this error Oauth error invalid_request: The redirect_uri is missing or not whitelisted

After i enter: https://xxxxxxxxx.herokuapp.com/install.php?shop=ecommerce-52.myshopify.com

Please help me with this.

myjanky commented 8 years ago

Please see other threads in issues. There is some good info in there to get you out of the oauth issue.

Post a screenshot of your developer dashboard for your app. You may have a setup issue. Many times I see it this as a misconfig.

subhanahmed047 commented 8 years ago

Here is my developers dashboard app settings untitled

myjanky commented 8 years ago

Your application URL is the callback URL, the redirection URL needs to point to where you want the user to go after oauth. I think this may cause a redirect loop as the app keeps passing it back to the redirect which is the same page you are loading. (this can be done like this but you need to test a query param to get you to step 3 of the process.).

first thing I would do is make the redirect point to get_products.php also you should debug by changing this on line 13 of install.php echo "<script> top.location.href='$install_url'</script>"; to this echo $install_url; See where it is trying to take you. you can inspect the url for the correct params see this https://www.shopify.com/partners/blog/17056443-how-to-generate-a-shopify-api-token

subhanahmed047 commented 8 years ago

I'm stuck here http://stackoverflow.com/questions/36234627/shopify-generating-a-shopify-api-token-this-request-is-not-from-shopify

Can you please help.

myjanky commented 8 years ago

What is the install_url var?

I replied to your stack overflow question.

subhanahmed047 commented 8 years ago

i'm following https://www.shopify.com/partners/blog/17056443-how-to-generate-a-shopify-api-token

Install url is https://xxxxxxxx.herokuapp.com/install.php

myjanky commented 8 years ago

That article is approaching 2 years old from shopify. I did a recent test and localhost will not work as it is not ssl protected the redirect simply fails. If you are using this lib, try dumping your $install_url var and copy/paste into your browser. Navigate to that url manually and post it back here so I can inspect it. (you can delete or mask the domain, I just need to see query string).

subhanahmed047 commented 8 years ago

https://xxxxxxx.myshopify.com/admin/oauth/authorize?client_id=846066b8087ac3fb54d69377e3a9fe58&scope=read_orders,read_products&redirect_uri=https%3A%2F%2Fxxxxxxxx.herokuapp.com%2Fgenerate_token.php

here is my install URL.

subhanahmed047 commented 8 years ago

It successfully generates a token when it redirects to generate_token.php but after that, the check that md5($signature_data) and $signature are same fails.

Here is my redirect URI variable that is appended to install_url

$redirect_uri = "https://xxxxxxxxx.herokuapp.com/generate_token.php";

Here is install_url var

$install_url = "https://" . SHOP_NAME . ".myshopify.com/admin/oauth/authorize?client_id=" . API_KEY . "&scope=" . SCOPES . "&redirect_uri=" . urlencode($redirect_uri);

myjanky commented 8 years ago

I think you need to start from scratch and not follow the 2 year old article https://www.shopify.com/partners/blog/17056443-how-to-generate-a-shopify-api-token (this will work but not on localhost and not mixed with the code from shopify_app-skeleton.) You should use one or the other to get an understanding how the oauth works. The article was only intended as a tutorial to help you see the steps that this app skeleton takes to install the app. Separate the two.

Also, I noticed that you are using heroku which is great but this library uses composer to make sure all dependencies are installed. Can you post your launch logs from heroku? Maybe composer is failing and not installing all your components.

daniel-farina commented 8 years ago

Guys follow this steps:

  1. Clone & upload to your server Example: mysite.com/app/myapp
  2. Run composer update
  3. Create a new app in your Shopify's developer's account (https://developers.shopify.com/)
    • Callback URL: http:mysite.com/app/myapp/oauth.php
    • Api Key & Secret: Goes in your conf.php
  4. You are ready to install the APP

    • Edit and add this to conf.php

      define('REDIRECT_URL', 'http://mysite.com/app/myapp/oauth.php');

      (You can define the redirect url to whatever you want for now, in this case I'm sending them back to the website my app is hosted at.) !!!!!IMPORTANT!!!!!!! You must define this\ exact url **in your APP settings in your Shopify developer account. (Redirection URL (required)), else you will get the the redirection address not white listed error.

    • Change this line on oauth.php (I dont know why the redirect_url is not present here but add it just to get this work)

    -$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')); to -$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'),REDIRECT_URL);

_Edit: Quick note, if you use underscores on your redirect file name, it might cause random errors. _

What is next? Learn and play with this to create a useful app. Now I'm trying to figure out how to modify the behavior of my shopify fronted with this app, for example what if I would like to change the rates that are shown during the checkout page, would I need to create a embedded app? Any suggestions or guidance would be appreciated! I will post my findings here.

myjanky commented 8 years ago

@daniel-farina Unless you have a Plus account on Shopify, you can not change anything on the checkout with the API. Your instructions are great and should help @incredibleX but this has been covered multiple times in other issues of this project. see https://github.com/phpish/shopify_app-skeleton/issues/9#issuecomment-147216952

The embedded app just keeps the admin in the backend of the shop instead of opening a new tab. For example when I click the app in the apps section here: screenshot 2016-03-30 at 9 05 03 am It opens in the backend. screenshot 2016-03-30 at 9 07 27 am

I think you are needing an App Proxy URL setup so you can feed content (rate changes in your example) to the frontend of the shop.

daniel-farina commented 8 years ago

@myjanky

Thank you for your feedback.

So the app being embeded or not it still has the same level of access to Shopify. Makes sense!

I think you are right about App Proxies. I'm reading this: https://docs.shopify.com/api/tutorials/application-proxies

and this is exactly what I'm looking for. Its a entire beast by itself. Lets see how far I can get.

myjanky commented 8 years ago

This is how I do it:

var base_urlc = window.location.hostname; var window_width = $(window).width(); if ($('#customized').length > 0 ){ $('#customized').css({'width':'100%'}); // detect container width var width_canvas = $('#customized').width(); var product_id = $('#customized').data('product'); $.get( '/products/' + product_id + '.json', function(xhr,status){ data_params = JSON.stringify(xhr); data_param=JSON.parse(data_params); var product_id = data_param.product.id; var img_lrg = Shopify.resizeImage(data_param.product.images[0].src, 'large'); var target_html = '<iframe id="customized-iframe" src="//' + base_urlc + '/apps/customize?shop=' + Shopify.shop + '&product_id=' + product_id + '&image=' + img_lrg + '" frameborder="0" scrolling="no" style="display:block;" width="100%" />'; $('#customized').html(target_html); });}

subhanahmed047 commented 8 years ago

@daniel-farina I followed everything you suggested. I clone and uploaded phpish/shopify_app-skeleton on the server.

Edited everything, My App callback url is exactly the same as redirect url but when i browsed to install.php with shop, like:

xxxxxx.com/shopify/install.php?shop=xxxxxxx.myshopify.com

I get this

Oauth error invalid_request: The redirect_uri is missing or not whitelisted

I've print_r my permission url and it is:

https://xxxxxxxx.myshopify.com/admin/oauth/authorize?client_id=1d39a01f5b632774ee95f9c042a99902&scope=read_content,read_themes,read_products,read_customers,read_orders,read_script_tags,read_fulfillments,read_shipping&redirect_uri=http%3A%2F%2Fxxxxxxxxx.com%2Fshopify%2Foauth.php

subhanahmed047 commented 8 years ago

@myjanky I've cloned heroku git repo to my local system many times to see if everything is okay, and I havn't seen any composer issue.

myjanky commented 8 years ago

Have you tried entering in this URL when logged in to shopify? Just navigate to this URL and see if it allows you to login. (you may have to change your redirect by removing ouath.php)

https://xxxxxxxx.myshopify.com/admin/oauth/authorize?client_id=1d39a01f5b632774ee95f9c042a99902&scope=read_content,read_themes,read_products,read_customers,read_orders,read_script_tags,read_fulfillments,read_shipping&redirect_uri=http%3A%2F%2Fxxxxxxxxx.com%2Fshopify%2F

subhanahmed047 commented 8 years ago

Yes, i'm logged in, but still getting this error

subhanahmed047 commented 8 years ago

Yes it asks me to login first, but after login error page apears. The callback url is to oauth.php

Here are my App Settings: untitled

Here is my redirect URI:

define('REDIRECT_URL', 'https://xxxxxxxxx.herokuapp.com/oauth.php');

myjanky commented 8 years ago

define('REDIRECT_URL', 'https://xxxxxxxxx.herokuapp.com/oauth.php'); Make sure you change line 18: $permission_url = $permission_url . '&redirect_uri=REDIRECT_URL' as suggested above as well. You can save the variable in conf.php to make them global if you decide to add more redirects.

subhanahmed047 commented 8 years ago

Here is my permission Url

$permission_url = shopify\authorization_url($_GET['shop'], SHOPIFY_APP_API_KEY, array('read_content', 'read_themes', 'read_products', 'read_customers', 'read_orders', 'read_script_tags', 'read_fulfillments', 'read_shipping'),REDIRECT_URL);

I've Even tried it this way: Changing line 18 to: $permission_url = $permission_url . '&redirect_uri='.REDIRECT_URL;

but no luck,

myjanky commented 8 years ago

it has to match here as well. it can not be different. screenshot 2016-03-31 at 10 56 33 am

subhanahmed047 commented 8 years ago

Thanks a Lot for your kind support and patience :) That worked. :+1:

myjanky commented 8 years ago

awesome. I am glad it worked for you. Let me know if you need anything else.

subhanahmed047 commented 8 years ago

Sure, You're awesome :)

Help will save the world :earth_asia:

daniel-farina commented 8 years ago

@incredibleX Than you for your help.

I got this sample app to work. Its very useful!

Dan

vdkhatri commented 8 years ago

Hello,

I have followed all the steps and Installed App into Store. But after installed when I click on the store it redirects to the another tab. I have attached image of my App "Save & Share" on Store:

app

When I click on "Save & Share" App, then 2 urls are swapping continuously in one tab. Below 2 URLs are swapping:

1.) http://localhost/shopify/app1/new_prj/install.php?code=2bfb00fb8cf20266d75e19fd504c6613&hmac=fa6a3e4d4b43ea9738bb4622e8ffa7e1d6088af1cbec3ccb85d03673364d1b63&shop=fashionstar-3.myshopify.com&signature=bc8a24843a5c02d260fa8232e5221b19&timestamp=1462967146

2.) http://localhost/shopify/app1/new_prj/oauth.php?hmac=f3b4cbe54205cefe0b7a1fac0654ded722affd537f0d3ab1d7c52134b6519eb4&shop=fashionstar-3.myshopify.com&signature=d07043326df770b3db45a5e0810a41b8&timestamp=1462967303

Please give me solution. Why these two URLs are swapping in the single tab? I have no idea where is the problem.

myjanky commented 8 years ago

It looks like you may have an SSL problem and a redirect problem. I can not say for sure what your exact error is without more information on your code.

One thing is that it is opening in a new tab. Do you have the embedded app checkbox check in the partners dashboard? Are you using a redirect?

read here https://help.shopify.com/api/sdks/embedded-app-sdk/getting-started (you will want to use the oauth method and not the auth method)

vdkhatri commented 8 years ago

Thanks for the response.

I have used the same code for the App which is given by shopify_app-skeleton. I have add define('REDIRECT_URL', 'http://localhost/shopify/app1/new_prj/install.php'); into conf.php file. Still I have the problem to access App into the store and getting the same problem.

Sorry, I get that error after click on "Install App" from the Store dashboard. Means after running this link: http://localhost/shopify/app1/new_prj/install.php?shop=fashionstar-3.myshopify.com It redirects to store screen where a user clicks on "Install App".

app1

After click on "Install App" it gives me blank tab and swipes those 2 links.

My redirect Link is: http://localhost/shopify/app1/new_prj/install.php

I don't know what is the problem.

myjanky commented 8 years ago

It looks like you may have an SSL problem and a redirect problem. Fix this first. I was never able to successfully use localhost or a self signed cert. You need HTTPS

eusthace811 commented 7 years ago

How to make my app embeddable and public not listed?

I would like to add a javascript to the theme/store. Any example?

I would need some help :S

myjanky commented 7 years ago

Embedded as in JS loads your App? If so you can have your app add a js script tag to the theme which loads your app js. Then js can talk to your server and get content or data. As for public not listed, just give your app users the install URL. No need to list in the App marketplace.

here is the docs https://help.shopify.com/api/reference/scripttag here is an example but it is using a C# library and not php. https://nozzlegear.com/blog/the-developers-guide-to-shopify-script-tags