Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shopify app redirect URL after install shows token number instead app name #23

Open
alexandprivate opened this issue Aug 1, 2016 · 116 comments

Comments

@alexandprivate
Copy link

alexandprivate commented Aug 1, 2016

Hi Larry, I am having and issue now, after my app have been authorized by the store and the installation process ends, I get redirect to the store administrator to my app view in the iframe but, the URL showed is containing the token number and instead the app name like this

https://hekities.myshopify.com/admin/apps/token-number-here/index.php

when it should be like this

https://hekities.myshopify.com/admin/apps/my-app

Also after load my app view the store remain loading like if were calling for more resources, even when my app shows perfectly. On the other hand when I leave this view and go to general app view in at store and click on my app I get the perfect URL, I mean this URL:

https://hekities.myshopify.com/admin/apps/my-app

but isn't passing the token number and shows this in the iframe:

Invalid Request! Request or redirect did not come from Shopify

so is going for the die part of the function because is nor passing the token number !

well this are two issues really I attached the view from the error when I click the app from the store admin and my app config
hekities apps shopify

edit app settings for shippingfy shopify partners

@myjanky
Copy link

myjanky commented Aug 1, 2016

Your App URL does not need to be oauth. It can be like the sample "get_products.php"

Usually, I would recommend changing line 31 of oauth.php and have a header("_where you want the app to go after auth_").

If you are getting to step 3 http://docs.shopify.com/api/authentication/oauth#confirming-installation
then you may have issue with SSL or you do not have a mechanism to store the auth code.

If all security checks pass, the authorization code can be exchanged once for a permanent access token. The exchange is made with a request to the shop.

POST https://{shop}.myshopify.com/admin/oauth/access_token
With {shop} substituted for the name of the user’s shop and with the following parameters provided in the body of the request:

client_id
The API Key for the app. (See the credentials section of this guide).
client_secret
The Shared Secret for the app. (See the credentials section of this guide).
code
The authorization code provided in the redirect described above.
The server will respond with an access token:

{
"access_token": "f85632530bf277ec9ac6f649fc327f17",
"scope": "write_orders,read_customers"
}
access_token is a permanent API access token that can be used to access the shop’s data as long as the client is installed. Clients should store the token somewhere to make authenticated requests for a shop’s data.

@alexandprivate
Copy link
Author

The thing is that if I change the App URL to other than oauth.php the app don't wont install

@alexandprivate
Copy link
Author

when the app url and the redirect url both point to oauth.php the app installs fine but if I change the app url for example to get_products.php the app wont install at all

@alexandprivate
Copy link
Author

the SSL is working fine the problem is when I click on the banner of the app from the store admin

@myjanky
Copy link

myjanky commented Aug 1, 2016

I see what you mean.

Without looking at your code, it is hard to tell what the issue is exactly. If you keep oauth.php as your app URL then you will have to change line 31 to a header() type redirect so that you end up in your app after the auth.

@alexandprivate
Copy link
Author

alexandprivate commented Aug 1, 2016

Definitely I cant change the app url to other than oauth.php and I also have the redirect in my code in line 31 redirection to index.php and thats working after iinstall process, the problem is that when I click at the banner of my app in from the store administration is not passing the token here is my oauth.php code:

top.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']; header('Location: index.php'); exit(); // redirection here } 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()); } ``` ?>

@alexandprivate
Copy link
Author

alexandprivate commented Aug 1, 2016

to achieve the app installation the app url have to point to oauth.php then when you click on the app from the store admin there is no generating the token and the redirection goes from line 11 of the oauth.php

@myjanky
Copy link

myjanky commented Aug 1, 2016

What does your index.php look like?

What is supposed to happen is that after your app installs, you ask shop for a permanent API key that you store and use it for all future API calls instead. Once you have the permanent API key, you do not have to oauth anymore.

what's the URI showing in your browser during the error. (you can mask for security).

@alexandprivate
Copy link
Author

this is the URL
https://hekities.myshopify.com/admin/apps/my-app-name in the error when I click on the app from store administration

@myjanky
Copy link

myjanky commented Aug 1, 2016

https://help.shopify.com/api/guides/authentication/oauth#asking-for-permission

http://wern-ancheta.com/blog/2013/11/09/getting-started-with-shopify-app-development/

the second uses a different library but may help overcome some of the issues you are having.

What is in your index.php?

@alexandprivate
Copy link
Author

alexandprivate commented Aug 1, 2016

Dont know why I cant place the code here wait

@alexandprivate
Copy link
Author

alexandprivate commented Aug 1, 2016

Larry since I have to keep the app url pointing to oauth.php otherwise the app wont install, this also means that after installation the app redirects to oauth and oauth redirects to index.php since there everything ok, but when I click on the banner of my app from the store administration, shopify redirects me to oauth.php(cuz is the app url with redirection to index.php) again but shopify isn't generating any token that's why in that scenario end in line 11 of the oauth.php.

what can I do with that ?

@alexandprivate
Copy link
Author

Larry the real problem is that Shopify isn't generating the token when I click on the banner app from the store administration

@alexandprivate
Copy link
Author

Shopify isn't generating the token when I click on the banner app from the store administration once my app have been installed.

@myjanky
Copy link

myjanky commented Aug 1, 2016

Shopify does not generate a new access token unless the app is uninstalled and reinstalled.
I believe you are misunderstanding Oauth and how it works. Since you changed the is_valid_request function, you may be experiencing issues due to Shopify deprecating the signature parameter.

Step 4: Making authenticated requests

Now that the client has obtained an API access token, it can make authenticated requests to the REST API. These requests are accompanied with a header X-Shopify-Access-Token: {access_token} where {access_token} is replaced with the permanent token.

@alexandprivate
Copy link
Author

I thinks I lost you... see after the app have been installed I click in the app banner from the store administration and that drive me to oauth.php as expected but shows the error of the line 11 of the oauth.php because is not passing the token verification

@myjanky
Copy link

myjanky commented Aug 1, 2016

That is where your issue is. You do not want your App url to keep re-Authenticating through oauth.php. It already has authenticated and it's up to your app to determine if the request are coming from shopify or not. After a successful authentication, you can ask shopify shop to send you a permanent token to reuse. At that time you no longer need to keep requesting the authorization code but instead make sure the access token is stored in $_SESSION ----->
$_SESSION['oauth_token']

dump that var and see if it is getting set.

@myjanky
Copy link

myjanky commented Aug 1, 2016

Also,

Oauth.php is very simplified and has a basic try catch for errors. Since shopify has a 3 step auth process, this is what usually confuses everyone who attempts to use this lib. And things have changed some which makes your lib not exactly this lib....

@myjanky
Copy link

myjanky commented Aug 1, 2016

Here is a good article about Oauth and the mechanics.
https://aaronparecki.com/2012/07/29/2/oauth2-simplified#roles

@alexandprivate
Copy link
Author

alexandprivate commented Aug 3, 2016

problem solve Larry thanks ! hey I find that the loader bar in my shopify store administration never ends loading when I open my app any idea why ? how can I solve this ?

@myjanky
Copy link

myjanky commented Aug 3, 2016

Awesome. Curious to know what issue was holding up your app launching in the admin panel?

For your app to work in the backend of Shopify you need to enable Embedded App in your developers/partners dashboard. Then you need to link the embedded app js on the page loading (i.e. get_products.php or whereever your app loads)
https://help.shopify.com/api/sdks/embedded-app-sdk/initialization

You will find code snippets to add to your page to get you started.

@alexandprivate
Copy link
Author

well as you know I use as App URL oauth.php because without that my app simply don't install dont know why but it is that way so, after install shopify try to call oauth again and when I click the app from the admin panel happens the same thing, so I check for that error and solve the problem redirecting to my index.php from the oauth and thats it

@alexandprivate
Copy link
Author

about the loading in fact my app page loads ok inside the iframe in my admin store view but even after my app loads the blur loading bar in shopify backend keeps loading and visible ... never finish loading, never gets to the end.

@myjanky
Copy link

myjanky commented Aug 3, 2016

Got it. You were in a redirect loop (code getting to the same place in oauth.php instead of a handler to direct to index.php if session has perm token).

Let me know if you need more help with the embedded app code.
Also, I am thinking of releasing a new App skeleton based on this work that is easier for app developers that are getting started to get setup more quickly and easier. (allowing for dev time instead of debug time.)

@alexandprivate
Copy link
Author

by the way embed app is enable in my partner admin

@alexandprivate
Copy link
Author

great !!!! just keep me posted about the new skeleton.

@myjanky
Copy link

myjanky commented Aug 3, 2016

You do not absolutely need to use the embedded app. It is just available to give app devs a more clean integration into shopify. Older apps prior to the embedded app was available to devs, simply open the app in a new tab.

You can disable embedded app in the partners dashboard to get the old behavior but many devs and shop owners like the integrated look of the embedded app.

@myjanky
Copy link

myjanky commented Aug 3, 2016

Also here is a style framework that will get your app looking like it should in shopify

http://seaff.microapps.com/

@alexandprivate
Copy link
Author

yeah ! thanks I got it, that's the one I am using for the frontend view thanks

@alexandprivate
Copy link
Author

alexandprivate commented Aug 3, 2016

I am using ShopifyApp.Bar.loadingOff() to kill loading spinner event but is not working, looks like the ready stage never happens

@alexandprivate
Copy link
Author

Exactly man !!!! I almost lose my head !!!!! Lol notice I just leave the
permission for scritptags and scritptags alone and boooom I realize it was
permissions since the hook for app Uninstaller work perfectly but not the
hooks related with products. You know now for future development. :)

On Tue, Oct 25, 2016, 13:56 Larry notifications@github.com wrote:

So the webhook also has to have permissions for the app to access those
resources?

makes sense but no documentation anywhere.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#23 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHVuD3wl7EAHqWhq9gnvDt1RF2PFt2rEks5q3lDXgaJpZM4JZuL4
.

@myjanky
Copy link

myjanky commented Oct 25, 2016

Thanks U will share with Shopify as well.

@alexandprivate
Copy link
Author

KK ! take care pal

On Tue, 25 Oct 2016 at 14:01 Larry notifications@github.com wrote:

Thanks U will share with Shopify as well.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#23 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHVuD8Ba1lSh_fz4eolQr1enERuXGD-8ks5q3lIGgaJpZM4JZuL4
.

@myjanky
Copy link

myjanky commented Oct 25, 2016

You too, thanks

@alexandprivate
Copy link
Author

Larry new issue ! well not an issue just a doubt a big one, my app uses webhooks in this case product create for example and it's working fine, so how could I get the ID of the store that sends the webhook ?? Think that the app will be in more than one store.

@myjanky
Copy link

myjanky commented Oct 27, 2016

In your app that creates the webhook request, you can append the webhook data with the Shop Id
https://help.shopify.com/api/reference/shop
and shop name also.

@alexandprivate
Copy link
Author

Yo my man Larry ! Buddy any advice to realize when a product is back to stock using webhooks ??? since the parameters of inventory_quantity and old_inventory_quantity have always the same value man ?

@myjanky
Copy link

myjanky commented Nov 1, 2016

What is the product's inventory_management and inventory_policy set to?

@alexandprivate
Copy link
Author

hekities products baby boy shirt shopify 1

@myjanky
Copy link

myjanky commented Nov 1, 2016

I think the webhook is not the right thing for this.
I suggest subscribing to an event
https://help.shopify.com/api/reference/event

The product event can notify your app of inventory updates.

@alexandprivate
Copy link
Author

and Larry how do I know when a product was sale? cuz I need to take control of product inventory quantity, manually and automatically , for example when a product was sale and the in stock quantity after every sale to check how many item the inventory has and when a client change the inventory amount to 0 manually

@myjanky
Copy link

myjanky commented Nov 1, 2016

I think there may even be a better way using transfers.

It is not well documented but the end point is /admin/transfers.json
There is also an undocumented webhook for this.

@alexandprivate
Copy link
Author

hummm

@myjanky
Copy link

myjanky commented Nov 1, 2016

There are really many different paths to the same goal with your project.

For example: You could create a custom collection that does something like this.
screenshot 2016-11-01 at 11 25 26 am

@myjanky
Copy link

myjanky commented Nov 1, 2016

screenshot 2016-11-01 at 11 26 53 am

@alexandprivate
Copy link
Author

is is any way I can set this from my the app to all products ?

@myjanky
Copy link

myjanky commented Nov 1, 2016

Yea. I would make the app create the custom collection(s) and query them when the app event is triggered to see which products have ended up in the collection(s) and have the app do any further processing on those products you require.

@alexandprivate
Copy link
Author

alexandprivate commented Nov 1, 2016

well remember I'm talking about a general app not a private one, likely to do a back to stock notification

@alexandprivate
Copy link
Author

Larry it is any way I can simulate an orders/paid from my development store ?

@myjanky
Copy link

myjanky commented Nov 1, 2016

yea, enable the test gateway in your checkout settings.

@alexandprivate
Copy link
Author

how I cant find it

@myjanky
Copy link

myjanky commented Nov 1, 2016

@alexandprivate
Copy link
Author

KK

@myjanky
Copy link

myjanky commented Nov 1, 2016

@alexandprivate
Hey man, I have been transitioning off PHP for shopify app dev for some time and have found Ruby and the official Shopify_App from shopify much more robust and refined. the app skeleton here has not had any major updates to the core Shopify.php. I am finding little to no issues with the official app.

If you are comfortable with Model View Controller programming than Ruby on Rails will just fit right in. But if not it is not that hard to learn and make work for you. It is night and day different than PHP (although there are tons of MVC php (cake ignite symphony etc....)

The main reason for me to move away from this lib is that any thing you want you have to write tons of code to get there but with the official Shopify_App, there is likely already a provision to do it or a Gem you can add quickly. Also ruby makes this a modular approach so separating code is quite easy.

http://shopify.github.io/shopify_app/

@alexandprivate
Copy link
Author

Thanks a lot man for your concern, really appreciate you help, thank you, I will give it a try to ruby, so be ready for issues here ! LOL, thanks pal.

@myjanky
Copy link

myjanky commented Nov 2, 2016

no problem. I think we should start a channel or use Shopify's IIRC (it has a web client so no worries there.). One issue with this php shopify api is that it has not had any movement other than our discussions in a while. (this is an open issue we are using for chat purposes.). Let me know if you want to hang out and chat on another platform or continue using this as that...

@alexandprivate
Copy link
Author

no problem man, whatever you feel confortable with, it could be an slack
channel or as you suggested the shopify IIRC (I dont know how to use this),
just let me know so we can help each other.

On Wed, 2 Nov 2016 at 11:45 Larry notifications@github.com wrote:

no problem. I think we should start a channel or use Shopify's IIRC (it
has a web client so no worries there.). One issue with this php shopify api
is that it has not had any movement other than our discussions in a while.
(this is an open issue we are using for chat purposes.). Let me know if you
want to hang out and chat on another platform or continue using this as
that...


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#23 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHVuDwfLf_g7glQPEBNkoPrNBW_-s2ebks5q6L4NgaJpZM4JZuL4
.

Alex

@myjanky
Copy link

myjanky commented Nov 3, 2016

https://shopifytalk.slack.com

may need your email to invite.

@alexandprivate
Copy link
Author

hello@alexdesignfor.me let's do it !

@HiralShah91
Copy link

Hello

I'm facing same issue for outh.php
After installing app successfully while I'm clicking on app name from shopify admin it again redirects to outh.php

I have to keep the app url pointing to oauth.php otherwise the app wont install, this also means that after installation the app redirects to oauth and oauth redirects to index.php since there everything ok, but when I click on the banner of my app from the store administration, shopify redirects me to oauth.php and again it is checking for "is_valid_request". which results "Invalid Request! Request or redirect did not come from Shopify"

Please help :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants