phpish / shopify_app-skeleton

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

Oauth error invalid_request: The redirect_uri is missing or not whitelisted #9

Open reivax opened 9 years ago

reivax commented 9 years ago

I seem to be getting an error now when using the SDK: Oauth error invalid_request: The redirect_uri is missing or not whitelisted

my callback URL is oauth.php as explained in the readme

anyone seeing the same thing? Saw some comments that shopify changed the handshake a couple months ago...

reivax commented 9 years ago

never mind I figured it out: the redirect URL in oauth.php is missing the redirect param which is necessary now I suppose. on line 18: $permission_url = $permission_url . '&redirect_uri=YOUR_REDIRECT_URL'

add an entry in conf.php that has the redirect url from the app you created on shopify and you should be ready to go...

ghost commented 9 years ago

Im stuck on this in my browser with a blank screen

https://quiet-basin-5290.herokuapp.com/?hmac=72a9e3098da74b5588a840f50efe4fa78044d83f3fb3c375697a77de540b277d&shop=getonfleek.myshopify.com&signature=5b8318b61e41f04188746b6843ffd6a6&timestamp=1445461311

you got past that. Any clues?

myjanky commented 9 years ago

@tynichol what is your redirect uri set to in the partners dashboard

Also it looks like you still have the blank index.html file in the project. That is the file that you need to customize for your app. either you are not redirecting to the correct uri or you are and it is pointed at index.html. which is a blank page.

ghost commented 9 years ago

hey @myjanky long time. I started a ruby app but dont have time for the learning curve. my redirect is https://quiet-basin-5290.herokuapp.com/oauth.php

I think something is wrong with composer as well. Im getting this when I push to heroku:

WARNING: Your Composer vendor dir is part of your Git repository remote: That directory should not be under version control; only your remote: 'composer.json' and 'composer.lock' files should be added, which remote: will let Composer handle installation of dependencies on deploy. remote: To suppress this notice, first remove the folder from your index remote: by running 'git rm --cached vendor/'. remote: Next, edit your project's '.gitignore' file and add the folder remote: '/vendor/' to the list. remote: For more info, refer to the Composer FAQ: http://bit.ly/1rlCSZU

myjanky commented 9 years ago

@tynichol https://quiet-basin-5290.herokuapp.com/oauth.php Should be your callback url (or Application URL(required) when viewing from edit settings).

Your redirect could be any one of the examples given in the repo, such as create_product.php, get_products.php and get_shop.php. But if you have the redirect uri in the settings set to https://quiet-basin-5290.herokuapp.com/oauth.php then it is just gonna take you to the oauth page which it has already completed authorization. Shopify gets confused because it is not getting the correct parameters for Step 2: http://docs.shopify.com/api/authentication/oauth#asking-for-permission Make sure you change line 18: $permission_url = $permission_url . '&redirect_uri=YOUR_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.

myjanky commented 9 years ago

As for your second issue, I think if you are uploading the composer files to heroku it can get confused. If you have locally cloned all the dependencies such as phpish/shopify than you should be fine. Just delete the composer files and let heroku build run blind.

ghost commented 9 years ago

All works now! Thanks @myjanky you are a patient man!

myjanky commented 9 years ago

Not a problem. Let me know if you are having further issues. Glad to help.

FWIW, I have used all the shopify API libs out there and have even custom made my own. It just really depends on what you are after and for me what the other devs I work with are comfortable using. This one is pretty good as it is proper OOP, lightweight and the coding convention is superb. The only thing it lacks at this level is session management but if you are only gonna install the app in one store than you can do away with sessions and have it all DB driven.

ghost commented 9 years ago

@myjanky Well crap now that I changed it to get_products its not working.

call back = https://shielded-inlet-9096.herokuapp.com/oauth.php redirect = https://shielded-inlet-9096.herokuapp.com/get_products.php line 18 in oauth = $permission_url = $permission_url . '&redirect_uri=https://sheilded-inlet-9096.herokuapp.com/get_products.php';

getting the oauth error again

what the f david blaine

ghost commented 9 years ago

and this is my address

https://getonfleek.myshopify.com/admin/oauth/authorize?client_id=cc70b53f12559ae0a47c652f389a0a6a&scope=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_uri=https://sheilded-inlet-9096.herokuapp.com/get_products.php

myjanky commented 9 years ago

I get this error when going to your redirect.

GET [uri] => https:/admin/products.json

ghost commented 9 years ago

Thats because you are skipping auth. When you go to https://shielded-inlet-9096.herokuapp.com/install.php?shop=getonfleek.myshopify.com it get's token but then it wont clear the redirect

myjanky commented 9 years ago

I am using my shop to test your app so I get a token. It errors out due to redirect_uri is missing or not whitelisted. We know it is there in the URL but I can not check your settings in the back end. Something has changed. were you able to get to the install application page that auths the app? If so you should be able to use that token for get_products.php

ghost commented 9 years ago

Like the instructions say I go to https://shielded-inlet-9096.herokuapp.com/install.php?shop=getonfleek.myshopify.com

then it automatically takes me to the redirect get_products where I get the error

ghost commented 9 years ago

Here are my settings screen shot 2015-10-22 at 11 08 33 am

myjanky commented 9 years ago

I am working on a heroku instance I am going to share with you. I noticed you also have an unanswered issue in ohShopify

ghost commented 9 years ago

ya I was trying that interface as well. It seems to have a lot of deprecated issues and no support

ghost commented 9 years ago

what i noticed with heroku is I didnt build the composer file, I let heroku do that on push. Then it gets past the 500 error

myjanky commented 9 years ago

OK looks like line 15 of install.php is not returning https

change this: echo "script> top.location.href='$install_url'/script>"; to this: echo $install_url;

to debug the script. You will see the output and can copy the address and use HTTPS instead. go here after entering your shop http://tynichol.herokuapp.com/install.php?shop= and you will see the url with http instead of https

The bug is on line 9 of the phpish/shopify.php you may need to load the dependencies without composer to be able to change the code in that file. Also if you need to remove the vendor folder to allow heroku to build just run git rm -r --cached vendor/

ghost commented 9 years ago

cant I append it in install.php when if I change shopify.php and let heroku run without vendor it will build the original version of shopify.php without the changes

myjanky commented 9 years ago

Its hard coded in shopify.php return "http://$shop/admin/api/auth?api_key=$api_key";

myjanky commented 9 years ago

You could override the function within install.php

ghost commented 9 years ago

$url = str_replace( 'http://', 'https://', $install_url ); echo "";

trying this now

myjanky commented 9 years ago

That works.

Just curious as to your workflow. Do you commit changes and PUSH after every edit before testing?

ghost commented 9 years ago

yes. I just tried it. I get the https added but it is still not working

myjanky commented 9 years ago

Also, mine works if you want the heroku app I can give it to you

ghost commented 9 years ago

Sure! I really am frustrated cause I don't know whats going on. How can I grab it?

ghost commented 9 years ago

Wow. Im an idiot. there is a difference between shielded and sheilded. I had it misspelled in my oauth.php

myjanky commented 9 years ago

i need your email addy if you want the heroku build shared but I can also walk you step by step to get a working instance on your side so you will be able to sync back to heroku if needed.

myjanky commented 9 years ago

Did you get it working?

ghost commented 9 years ago

App is installed successfully but get this at redirect

phpish\shopify\CurlException: [6] Could not resolve host: https in /app/get_shop.php on line 14Array ( [method] => GET [uri] => https:/admin/shop.json [query] => [headers] => Array ( [X-Shopify-Access-Token] => [content-type] => application/json; charset=utf-8 ) [payload] => ) Array ( )

myjanky commented 9 years ago

get_shop.php has a problem when trying to redirect to it. I can access it after I see the App installed Successfully message from oauth.

I replaced line 31 echo 'App Successfully Installed!'; with echo "script> top.location.href=https://tynichol.herokuapp.com/get_products.php/script>";

ghost commented 9 years ago

ya i never get the app successfully installed message

ghost commented 9 years ago

after researching this, it seems to be an issue a lot of people are having

ghost commented 9 years ago

Any luck?

myjanky commented 9 years ago

sorry had a management meeting with my staff.

can we move this to a iirc?

I can walk you through a clean install that works.

https://webchat.freenode.net/

shopify

mariuspo15 commented 9 years ago

i'v solved this by adding redirect_uri parameter to authorization_url() method in oauth.php file (line 17):

$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://dev.mydomain.com/app/oauth.php');

important: redirect_uri should be the same like in settings

Image of setttings

navalevivek commented 8 years ago

Hi, How do I add an entry in oauth.php for redirect uri , that has the redirect url from the app you created on shopify.

You mean, need to add code like below like this or what else, please suggest

define('REDIRECT_URI', 'http://my-domain-namet/directory-name/index.php');

myjanky commented 8 years ago

yes

navalevivek commented 8 years ago

Thanks a lot, will try to add it in oauth.php

gauravkumar60 commented 8 years ago

Hello, I installed the app but it show me error phpish\shopify\CurlException: [7] Failed to connect to dblgaurav.myshopify.com port 443: Connection timed out in /home/dbuglndz/public_html/shopifyapp/oauth.php on line 26Array ( [method] => POST [uri] => https://dblgaurav.myshopify.com/admin/oauth/access_token [query] => Array ( ) [headers] => Array ( ) [payload] => Array ( [client_id] => 3fc246ff677ec014b4752e5d1472274f [client_secret] => e13db5c49e6f509227619c475b3d5db8 [code] => fbfd8ae374e1e05fa3f38c5b823cb319 ) ) Array ( )

during access token. Can you please help me with this.Thanks is advance

Thanks Gaurav

myjanky commented 8 years ago

Hi Gaurav,

I do not think this is an issue with shopify app skeleton. It looks like the server you have your code on can not create a curl connection to your shopify store. If you have a command line you can try to ping your store and troubleshoot the connection.

Oh and it is not generally a good idea to publish your secret key and access token. But I suspect you know that.

gauravkumar60 commented 8 years ago

Hi Myjanky,

Thanks for the reply. I checked the curl and its working fine. I also tried it on other server. But it return me same error. IS there any thing required to allow shopify for server access ?

myjanky commented 8 years ago

I do know that Shopify recently made SSL available to the entire Store and not just the checkout portion. This could be the port error it is complaining timing out.

try using a REST client to POST to https://dblgaurav.myshopify.com/admin/oauth/access_token

myjanky commented 8 years ago

Can you post a screenshot of your partners account app setup?

gauravkumar60 commented 8 years ago

yes sure just a sec

gauravkumar60 commented 8 years ago

http://prntscr.com/9yj0r6 This is my test trial account. You can access it via dbl.gaurav@gmail.com / asdasdasd

myjanky commented 8 years ago

this is the error I get screenshot 2016-02-03 at 9 38 14 am

I see the redirect_uri is missing from your code. Can you post the contents of your conf.php?

gauravkumar60 commented 8 years ago

yes let me add that.

gauravkumar60 commented 8 years ago

please check now. I added the redirect_uri