Introducing cookieless authentication beta with App Bridge

Thanks Dave, this is really good feedback. I think you’ve identified a few things we can do better:

Looking through this code. Wow. There are like 120 lines of code now so intermingled with cookies and validation and access and …

I agree 100% with this. The new JWT code in shopify_app is actually pretty minimal. The existing cookie code, especially with the Safari workarounds, is a nightmare to parse, however.

We made a choice early on to support the cookie-based and JWT flows operating simultaneously in the app. In theory this would be useful for apps transitioning from the cookie-based flow to the JWT flow. In practice I think it’s made the shopify_app code and process even harder to understand than it was before, and introduced the potential for weird edge cases.

I think we (the folks at Shopify working on this) should refactor the code in shopify_app and separate the two flows, so consumers can include a ShopifyApp::CookieAuthenticated module if they’re using the cookie-based auth, but use a new ShopifyApp::JWTAuthenticated module if they’re using JWT. That won’t change the code that’s needed in your app, but it will make it easier for folks digging into the shopify_app gem (such as yourself) to see what it’s doing and will insulate the new, leaner code from the mess that is the cookie-based module. We’re still in beta, so now’s the time to make a change like that.

JWT does nothing to help with install, so what about all those helper JS files to play with cookies? All done with?

You’re right that JWT doesn’t fundamentally change the OAuth/install flow.

That being said, when we built the cookie workarounds for Safari a couple years ago, we shoehorned them into the OAuth flow. This was a short-term cheap, long-term expensive decision. With the JWT pattern we don’t need any of those JS includes for the Safari workarounds, so we (the folks at Shopify working on this) should refactor so that we can use a much slimmed down OAuth/install flow with JWT and avoid including all that Safari workaround cruft unnecessarily.

Maybe it is time to fork this gem to one that is suited to React, JWT and go from there?

A separate gem may make sense. At the very least we should commit to separating the flows better within the existing gem. If, after doing that, we all think it would be useful to move the JWT logic into a totally separate gem, I’m not opposed to that.

So fine but now I am in the world of strictly using a front-end like React, and ensuring my backend is rigged to deal with JWT. I am not seeing that pattern in Rails, but perhaps I am wrong.

Putting the JWT aspect aside for a second, I think it’s pretty common these days to build the frontend using a JS framework and for the frontend to use an API provided by the backend to fetch the data needed to render the views. If the app is already architected in this “JS-rendered frontend, backend exposes API” pattern, then including the JWT is straightforward.

Recently we’ve been more forceful about recommending this pattern (you’ll notice the most prominent guide on shopify.dev suggests using Node/React, for example). We realize, however, that lots of people have built apps that are server-rendered. It’s not as turnkey to use it with these kind of apps, but it’s definitely doable.

I think what we can do is what you suggest: build better tools/examples for the server-rendered use case, and the Rails rendered case in particular.

Thanks again for your feedback on this. Most of our focus (and our early beta testers) has been single-page apps that are easier to implement JWT for. One of the things we’re hoping to learn as part of this public beta is what’s missing for folks with server-rendered apps. This is a great start!