-
-
Notifications
You must be signed in to change notification settings - Fork 377
Conversation
Upstream Changes
Upstream
Upstream
* 'jwt' of github.com:darrynten/laravel-shopify: Update unit tests
Upstream Changes
Fantastic @darrynten ! Definitely would help out people! I think a small wiki addition on how to set this up would be great after too. Tests are passing which is awesome, thanks. I was unaware of the billing screen issue, but passing in the input vars as you've done seems like a fine solution. From my end, stuff looks fine. I'm wondering for the API error responses though, should we just throw an exception? This way it can be handled alternatively by the user if they wish to with a custom render function. Something like: Edit: @darrynten Can you also shoot me an email for an aside thing I wanted to run past you. |
@osiset I've updated the PR to throw exceptions instead of returning plain responses, and ensure that JSON responses are returned if the All tests have been updated and additional tests have been added. |
@darrynten Thanks, I'll merge it! |
I'll look at tryin to add a wiki for this later the week. |
im just confused about the database part , when first opening the app how to deal with installation process ? |
Trying to understand how to make it work with server side rendered apps. |
seems like https://github.com/turbolinks/turbolinks is the way to go |
Maybe we can all assist on documenting this awesome feature :) I am not 100% sure I get how we switch to using JWT as authentication mechanisms in a new or existing project nor when exactly it is recommended or even possible. As far as I can see the relevant places to document this would be:
Unresolved question that I think is worth documenting: Authentication in generalThere are two aspects of authentication when developing Shopify apps:
When installing a new app the user goes through a rather cumbersome OAuth process as describe by Shopify here and the documentation of this package here. Essentially using the Once the app is installed correctly using OAuth then a Shopify Api Token will be saved in the Each time the App makes a RestAPI or GraphQL request to Shopify then it uses this API Token to authenticate. Now that the app is installed and the user has granted the app access to their Shopify account by going through the OAuth flow, then we need to know how to authenticate on every day use. There are mainly four interesting parts to take into account:
NOTE: How the result should look depends on wether or not the app is an Embedded App or not. Now for the use cases we can authenticate them differently:
@andreuka did you manage to find out how to use this properly on a service side rendered app (most obvious example would be a multi-page app using blade files)? Do anyone knows how this works with admin links? |
@bilfeldt Im using turbolinks to work with it. its not perfect and creating additional redirect when user visits first page of app. but it works. It would be perfect if we will get middleware which will check for HMAC auth OR Token auth is valid in 1 middleware. This is sample of code I using at the moment.
|
@andreuka Hello, I am having a hard time to understand your solution, why does the route has to middleware with auth.shopify? I thought we need an unauthenticated page to retrieve the session token, and then redirect to our authenticated page using that token? |
@darrynten Would you have a couple jot notes about implementation for this, off the top of your head, that I can take and turn into a wiki entry? |
Because you need to check whether the request to your app is authorized, e.g. if the app is loaded for the first time during the installation process. |
Yeah, but with latest updates its not relevant anymore as there is better way. |
Shopify JWT Authentication
Provides new auth.token middleware you can place on API endpoints.
See: https://shopify.dev/tutorials/authenticate-your-app-using-session-tokens
This means you can now build apps without cookies (see #522) and will no longer experience bugs like #443. It also allows for functionality requested for in #526 and #599 because Shopify does most of the hard work now, meaning issues like #588 (and everything else cookie related) is a thing of the past.
Usage
This package only covers the backend functionality changes.
I'm not submitting any frontend changes (creating an external package instead), so follow the frontend instructions in the Shopify documentation.
You can install some Vue-based frontend scaffolding to test this with: UnicornGlobal/laravel-shopify-vue.
Send the JWT you get from Shopify in the
Authorization: bearer <xyz>
header directly to any API endpoint secured with theauth.token
middleware.Don't forget to get a fresh JWT from Shopify on your frontend every 30 seconds so your token stays valid.
Changes
auth.token
/api/me
and plan list on/api/plans
The reason the phpunit and HMACs have changed is due to a bug that allowed the application to operate even when there was no Shopify API key set. This PR adds a key and secret to the phpunit.dist.xml file.
You must update your phpunit.xml file to include the missing env vars
Also fixes an issue where the billing screen sometimes didn't know which shop to load.
Resolves #551